【发布时间】:2019-01-08 10:44:48
【问题描述】:
我知道这对你来说可能听起来很愚蠢,但我现在正在通过互联网上的课程学习 Python,他们要求我们创建一种迷宫。
他们给出了一个“基本代码”,但是当我尝试运行它时,它说 FileNotFoundError: [Errno 2] No such file or directory: 'cartes',错误在 os.listdir(cards )。
我希望代码列出名为 cartes 的本地目录的内容,但我无法这样做,因为我收到 FileNotFoundError。
这是我正在努力解决的代码:
# -*-coding:Utf-8 -*
"""This file contains the main code of the game.
Run him with Python to start the game.
"""
import os
from map import Map
# We load the existing maps
maps = []
for file_name in os.listdir("maps"):
if file_name.endswith(".txt"):
path = os.path.join("maps", nom_fichier)
map_name = file_name[:-3].lower()
with open(path, "r") as file:
content = file.read()
# Map creation, to complete
# We display the existing maps
print("Existing labyrinths :")
for i, map in enumerate(maps):
print(" {} - {}".format(i + 1, map.nom))
# If there is a saved game, we display it, to complete
# ... Complete the program ...
【问题讨论】:
-
下次请在您的帖子正文中包含代码:)
-
你从哪里运行命令?我想我找到了问题
-
是的,错误在 os.listdit("cartes")
-
你能把你代码中的法语单词翻译成英文吗?
-
现在翻译成英文
标签: python python-3.x file