weixin_54770840
让我躺一下
采纳率0%
2021-02-27 14:35

pycharm出现Type Error

直接放代码:

for files,filepath,folders in os.walk(path):
    for file in files:
        size = os.path.getsize(os.path.join(filepath, file)) / 1024 / 1024  # 1024b=1kb 1024kb=1MB 1024MB=1GB
        os.remove(os.path.join(filepath,file))
Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/python.py", line 22, in <module>
    size = os.path.getsize(os.path.join(filepath, file)) / 1024 / 1024  # 1024b=1kb 1024kb=1MB 1024MB=1GB
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 76, in join
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not list
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • m0_38124502 我不喜欢这个世界 2月前
    for files,filepath,folders in os.walk(path):
    
    
        for file in folders:
    
    
            size = os.path.getsize(os.path.join(files, file)) / 1024 / 1024  # 1024b=1kb 1024kb=1MB 1024MB=1GB
    
    
            os.remove(os.path.join(files, file))
    点赞 评论 复制链接分享