|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import os
allfiles = os.listdir('G:\\phthon')
filedict = dict()
print(allfiles)
for each in allfiles:
if os.path.isfile(each):
filesize = os.path.getsize(each)
filedict.setdefault(each,filesize)
print(filedict)
for eachitem in filedict.items():
print('%s【%d bytes】'%(eachitem[0],eachitem[1]))
大佬可以帮我看下中间的for 循环哪里有问题嘛 我的字典里没有任何东西
应该用绝对路径,除非你事先 CD 到 'G:\\phthon' 路径下,然后再运行你的脚本。
- import os
- path = 'G:\\phthon'
- filedict = {}
- for each in os . listdir(path):
- x = os . path . join(path , each)
- if os . path . isfile(x):
- filedict[x] = os . path . getsize(x)
- for each in filedict . items():
- print('%s【%d bytes】'%(each[0] , each[1]))
复制代码
|
|