文件内容rolling.txt: There's a fire starting in my heart 我怒火中烧 Reaching a fever pitch and it's bringing me out the dark 熊熊烈焰带我走出黑暗 Finally, I can see you crystal clear 最终 我将你看得一清二楚 Go ahead and sell me out and I'll lay your ship bare 去吧 出卖我 我会让你一无全部 See
Python3.3下测试通过 获取文件大小 使用os.path.getsize函数,参数是文件的路径 获取文件夹大小 import os from os.path import join, getsize def getdirsize(dir): size = 0.0 for root, dirs, files in os.walk(dir): size += sum([getsize(join(root, name)) for name in files]) return size if __
1 #获取文件夹内的图片 2 import os 3 def get_imlist(path): 4 return [os.path.join(path,f) for f in os.listdir(path) if f.endswith('.jpg')] 5 6 img_path = get_imlist("database") 7 print(img_path)
from itertools import islice start = 1 # 跳过第一行idx=0,从idx=1开始读取文件 with codecs.open('data.json', encoding='utf-8') as fr: for idx, line in enumerate(islice(fr, start, None)): print idx, line