Questions tagged «listdir»

12
来自os.listdir()的非字母数字列表顺序
我经常使用python处理数据目录。最近,我注意到列表的默认顺序已更改为几乎毫无意义的内容。例如,如果我位于包含以下子目录的当前目录中:run01,run02,...,run19,run20,然后从以下命令生成列表: dir = os.listdir(os.getcwd()) 然后我通常会按以下顺序获得列表: dir = ['run01', 'run18', 'run14', 'run13', 'run12', 'run11', 'run08', ... ] 等等。该顺序曾经是字母数字。但是这个新订单已经存在了一段时间。 是什么决定这些列表的(显示)顺序?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.