This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# very ugly code, good boy dont copy this, hope | |
# 其实可以写成Chrome插件? | |
# 读入bilibili的播放列表的URL, 分拆出每一集的地址和标题 | |
# 貌似youtube-dl没法读出合适的下载名称 | |
i=1 | |
declare -a filenamearray |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf8 | |
import configparser | |
import os | |
import requests | |
UL_DASHBOARD_LICENSE_PATH = r'C:\Users\mluo\Downloads\UL DASHBOARD_test_licenseTXT.txt' | |
UL_DASHBOARD_LICENSE_PATH_USING = r'C:\Ullink\platform201610Full\-CleanUp-\ULDASHBOARD\conf\ul-dashboard-server.ini' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Target: | |
1、第1章 第1节 集合(1)2、第1章 第1节 集合(2)3、第1章 第1节 集合 | |
Purpose: | |
Search for "1、" and replace with newline plus that | |
Solution: | |
Search: (\d{1,3}\、) | |
Replace: \n\1 | |
----------------------------------------------------------------------- | |
Target: | |
第14章 第2节 第二类曲线积分与第二类曲面积分 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for filepath in filelist: # filelist中是文件路径的列表 | |
try: | |
with open(filepath, 'r') as f: | |
# 执行数据处理的相关工作 | |
pass | |
print('{} is processed!'.format(filepath)) | |
except IOError: | |
print('{} with IOError!'.format(filepath)) | |
# 异常的相应处理 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('name_age.txt', 'r') as fread, open('age_name.txt', 'w') as fwrite: | |
line = fread.readline() | |
while line: | |
name, age = line.rstrip().split(',') | |
fwrite.write('{},{}\n'.format(age, name)) | |
line = fread.readline() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 'I’m like a {} chasing {}.' | |
# 按顺序格式化字符串,'I’m like a dog chasing cars.' | |
a.format('dog', 'cars') | |
# 在大括号中指定参数所在位置 | |
b = 'I prefer {1} {0} to {2} {0}' | |
b.format('food', 'Chinese', 'American') | |
# >代表右对齐,>前是要填充的字符,依次输出: | |
# 000001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 'Life is short, you need Python' | |
a.lower() # 'life is short, you need Python' | |
a.upper() # 'LIFE IS SHORT, YOU NEED PYTHON' | |
a.count('i') # 2 | |
a.find('e') # 从左向右查找'e',3 | |
a.rfind('need') # 从右向左查找'need',19 | |
a.replace('you', 'I') # 'Life is short, I need Python' | |
tokens = a.split() # ['Life', 'is', 'short,', 'you', 'need', 'Python'] | |
b = ' '.join(tokens) # 用指定分隔符按顺序把字符串列表组合成新字符串 | |
c = a + '\n' # 加了换行符,注意+用法是字符串作为序列的用法 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""对于filter和map,在Python2中返回结果是列表,Python3中是生成器""" | |
import functools | |
map(lambda x: x**2, [1, 2, 3, 4]) # [1, 4, 9, 16] | |
map(lambda x, y: x + y, [1, 2, 3], [5, 6, 7]) # [6, 8, 10] | |
functools.reduce(lambda x, y: x + y, [1, 2, 3, 4]) # ((1+2)+3)+4=10 | |
filter(lambda x: x % 2, [1, 2, 3, 4, 5]) # 筛选奇数,[1, 3, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
moves = ['up', 'left', 'down', 'right'] | |
def move_up(x): # 定义向上的操作 | |
x[1] += 1 | |
def move_down(x): # 定义向下的操作 | |
x[1] -= 1 | |
def move_left(x): # 定义向左的操作 | |
x[0] -= 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Python并没有switch-case的语法,等效的用法要么是像上面一样用if-elif-else的组合,要么可以考虑字典""" | |
pets = ['dog', 'cat', 'droid', 'fly'] | |
food_for_pet = { | |
'dog': 'steak', | |
'cat': 'milk', | |
'droid': 'oil', | |
'fly': 'sh*t' | |
} |