debug日誌2(python)

來源:互聯網
上載者:User

標籤:常用操作   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)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.