[英]Pyhton2.7.10:Using os.listdir() to print file names in a folder,but get noting on shell
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 我想使用os.listdir()函数在文件夹上打印所有文件的名称,但是我运行了几次代码,这些在shell中什么都没有显示
I'm using OS X 10.11.6 我正在使用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)
You need to call function rename_files
when running the script. 运行脚本时,需要调用函数
rename_files
。 Add at the end of script: 在脚本末尾添加:
if __name__ == "__main__":
rename_files()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.