1. 程式人生 > >debug日誌2(python)

debug日誌2(python)

工作目錄 lap findall arc ESS 動態 正則表達 AR replace

1. 寫正則表達式時,為什麽要加上re.S

Make the ‘.‘ special character match any character at all, including a newline; without this flag, ‘.‘ will match anything except a newline.

2. 正則匹配中search,match,findall的差別

match()函數只檢測RE是不是在string的開始位置匹配,search()會掃描整個string查找匹配,也就是說match()只有在0位置匹配成功的話才有返回,如果不是開始位置匹配成功的話,match()就返回none。search()會掃描整個字符串並返回第一個成功的匹配。

下面這段話時官方文檔中對findall的解釋:

Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match.

3. 對文件夾的的常用操作,判斷是否以創建,不存在則創建,並把工作目錄設成當前文件夾下

        if not os.path.exists(KEYWORD):
os.mkdir(KEYWORD)
os.chdir(KEYWORD)

4. 其它常用操作

切片操作:i=i.replace(r"\\\\/","/")
i=i[:-2]

這兩步就可以完成所有字符串的替換。

完成動態路徑的指定:file_path=‘{0}.{1}‘.format(i,‘jpg‘)。

判斷某個類是否屬於某個數據類型:

if

isinstance(text,str) is not Ture

return None

debug日誌2(python)