鱼C论坛

 找回密码
 立即注册
查看: 3029|回复: 1

[已解决]30讲1题

[复制链接]
发表于 2021-9-23 20:10:05 | 显示全部楼层    本楼为最佳答案   
        应该用绝对路径,除非你事先 CD 到 'G:\\phthon' 路径下,然后再运行你的脚本。
  1. import os

  2. path = 'G:\\phthon'
  3. filedict = {}
  4. for each in os . listdir(path):
  5.     x = os . path . join(path , each)
  6.     if os . path . isfile(x):
  7.         filedict[x] = os . path . getsize(x)

  8. for each in filedict . items():
  9.     print('%s【%d bytes】'%(each[0] , each[1]))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-5 08:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表