您如何在Python中获得按名称排序的目录列表?
您可以调用os.listdir函数来获取目录内容的列表,并使用sorted函数对该列表进行排序。
例如
>>> import os
>>> list_dir = os.listdir('.')
>>> list_dir = [f.lower() for f in list_dir] # Convert to lower case
>>> sorted(list_dir)
['dlls', 'doc', 'etc', 'include', 'lib', 'libs', 'license.txt', 'news.txt', 'python.exe', 'pythonw.exe', 'readme.txt', 'scripts', 'share', 'tcl', 'tools', 'w9xpopen.exe']热门推荐
10 三八简短祝福语给婆婆
11 写给情侣祝福语 浪漫简短
12 见证求婚文案祝福语简短
13 妈妈给宝贝祝福语简短
14 送情侣生日祝福语简短
15 安徽疫情祝福语简短英语
16 老年 生日祝福语大全简短
17 老板端午简短祝福语大全
18 祝福语签名简短大全女生