Pyhton2.7.10:使用os.listdir()打印文件夹中的文件名,但是注意到shell(Pyhton2.7.10:Using os.listdir() to print file names

编程入门 行业动态 更新时间:2024-10-27 19:28:52
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

更多推荐

本文发布于:2023-08-03 00:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注意到   文件名   文件   夹中   listdir

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!