我试图从一个文件夹中导出六个图像,这六个图像被称为1。png,2.png等,但当我调用os.走着走着,要求打印出的文件,他们随机排列:
/Users/claudiabergeron/Documents/Python/Python_VideoGame_3.10/bin/python "/Users/claudiabergeron/Documents/Python/Tutoriels/Video games/Pygame/Platformer/help.py"
('/Users/claudiabergeron/Documents/Python/Tutoriels/Video games/Pygame/Platformer/graphics/character/run', [], ['4.png', '5.png', '6.png', '2.png', '3.png', '1.png'])
代码如下:
from os import walk
def import_folder(path):
for information in walk(path):
print(information)
import_folder('/Users/leolepage/Documents/Python/Tutoriels/Video games/Pygame/Platformer/graphics/character/run')
有人知道我该怎么做吗?
1条答案
按热度按时间j5fpnvbx1#
os.walk使用os。listdir和不能排序。我建议你用操作系统。listdir并排序: