Python Snippet

python按行读取文件,如何去掉换行符" "

for line in file.readlines():
    line=line.strip('
')

python没有substr,但可以用slice

s = line[11:22]

遍历文件夹。os.walk()返回一个三元素的tuple:当前路径、子文件夹名称、文件列表。

import os
def fun( path ):
    for root, dirs, files in os.walk( path ):
        for fn in files:
            print root, fn

  

  

原文地址:https://www.cnblogs.com/lautsie/p/3665224.html