Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t使用Python os.listdir在我的MAC上列出文件_Python - Fatal编程技术网

Can';t使用Python os.listdir在我的MAC上列出文件

Can';t使用Python os.listdir在我的MAC上列出文件,python,Python,尝试列出mac上的文件,但失败。我做错了什么 import os def rename_files(): file_list = os.listdir("/Users/right_user/right_folder/name_of_file") print (file_list) 这是脚本的一部分,用于对文件重新排序,从而实现该函数。 Tks 接受目录的路径,而不是文件的路径。如果您想列出right\u file所在目录中的所有文件,您应该执行file\u list=os.l

尝试列出mac上的文件,但失败。我做错了什么

import os

def rename_files():
    file_list = os.listdir("/Users/right_user/right_folder/name_of_file")
    print (file_list)
这是脚本的一部分,用于对文件重新排序,从而实现该函数。
Tks

接受目录的路径,而不是文件的路径。如果您想列出
right\u file
所在目录中的所有文件,您应该执行
file\u list=os.listdir(“/Users/right\u user/right\u folder”)

您似乎将一个文件交给了一个读取目录my bad的函数,我确实停在了文件夹,但没有输出,我只是没有注意,我把rename_文件称为wo/括号。谢谢你的帮助,非常感谢