標籤:常用操作 dal att match AC python character app ace
1. 寫Regex時,為什麼要加上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)