Я не могу запустить свой код Python, так как существует проблема с каталогом.Мой текстовый файл, который необходимо прочитать, также находится в той же папке, что и файл кода.
У меня есть другой текстовый файл в той же папке, что и программа.
Код:
def read_file():
try:
file = open('names.txt', 'r')
except FileNotFoundError:
print('File not found.')
print('Please make sure your file name/path is correct')
exit(0)
data = csv.reader(file, delimiter=',')
for line in data:
player = [line[0], int(line[1]), int(line[2]), int(line[3])]
all_players.append(player)
file.close()
Это сообщение об ошибке:
Traceback (most recent call last):
File "C:\Users\AK\OneDrive - RTC Education Ltd\Python\NewGame2.py", line 105, in <module>
play()
File "C:\Users\AK\OneDrive - RTC Education Ltd\Python\NewGame2.py", line 96, in play
read_file()
File "C:\Users\AK\OneDrive - RTC Education Ltd\Python\NewGame2.py", line 12, in read_file
file = open('names.txt', 'r')
IOError: [Errno 2] No such file or directory: 'names.txt'
[Finished in 0.113s]