Pyhton2.7.10:使用os.listdir()打印文件夹中的文件名,但是注意到shell(Pyhton2.7.10:Using os.listdir() to print file names in a folder,but get noting on shell)
我想用函数os.listdir()打印文件夹中的所有文件名,但我运行了几次代码,这些在shell中没有显示
我正在使用OS X 10.11.6
import os def rename_files(): #get file names from a folder file_list = os.listdir('/Users/luoluoluo/Desktop/Udacity/Program funfation with python/prank') print(file_list)
I want to print all files'name on the folder with the function os.listdir(),but I run the code for several time,these was nothing showed in shell
I'm using OS X 10.11.6
import os def rename_files(): #get file names from a folder file_list = os.listdir('/Users/luoluoluo/Desktop/Udacity/Program funfation with python/prank') print(file_list)最满意答案
运行脚本时需要调用函数rename_files 。 在脚本结尾添加:
if __name__ == "__main__": rename_files()参考资料
You need to call function rename_files when running the script. Add at the end of script:
if __name__ == "__main__": rename_files()The reference
更多推荐
发布评论