Python Mac-Can';找不到文件
有人为我编写了Python代码,但没有意识到我在Mac上 我得到以下错误:Python Mac-Can';找不到文件,python,Python,有人为我编写了Python代码,但没有意识到我在Mac上 我得到以下错误: Last login: Thu Jan 23 08:14:39 on ttys001 nraidervlan10:~ nraider$ cd '/Users/nraider/Downloads/Ten-code/' && '/usr/bin/pythonw' '/Users/nraider/Downloads/Ten-code/Master.py' && echo Exit statu
Last login: Thu Jan 23 08:14:39 on ttys001
nraidervlan10:~ nraider$ cd '/Users/nraider/Downloads/Ten-code/' && '/usr/bin/pythonw' '/Users/nraider/Downloads/Ten-code/Master.py' && echo Exit status: $? && exit 1
paths CWD=/Users/nraider/Downloads/Ten-code, CPD=/Users/nraider/Downloads/Ten-code/
Traceback (most recent call last):
File "/Users/nraider/Downloads/Ten-code/Master.py", line 145, in <module>
main()
File "/Users/nraider/Downloads/Ten-code/Master.py", line 114, in main
playerLists = loadFiles(CPD + "PlayerFiles/")
File "/Users/nraider/Downloads/Ten-code/Master.py", line 44, in loadFiles
except FileNotFoundError:
NameError: global name 'FileNotFoundError' is not defined
nraidervlan10:Ten-code nraider$
FileNotFoundError
在Python2.x中不存在;您确定使用的是Python 3吗?请阅读错误消息:NameError:未定义全局名称“FileNotFoundError”
-它来自Python本身,不是找不到文件,而是全局命名空间中缺少名称。如上所述,您应该使用python3run/usr/bin/pythonw-v运行此命令以查找Python版本,尽管Python只会在出现异常时尝试查找FileNotFoundError
,所以一旦使用了正确的Python版本,这里可能仍然有一个问题。谢谢大家。看起来我正在运行V3.8。
import csv
import os
import sys
import random
import time
CWD = os.getcwd()
#CPD = CWD.split('Ten-code')[0]+'Ten-code\\'
CPD = CWD.split('Ten-code')[0]+'Ten-code/'
#sys.path.append(CPD+'Modules\\Player_Class')
sys.path.append(CPD+'Modules/Player_Class')
#sys.path.append(CPD+'Modules\\Court_Class')
sys.path.append(CPD+'Modules/Court_Class')
print("paths CWD=%s, CPD=%s" % (CWD, CPD))
from playerClass import *
from courtClass import *
def loadFiles(directory):
fileList = os.listdir(directory)
playerLists = []
for file in fileList:
filePath = directory + file
try:
reader = csv.reader(open(filePath, 'r', encoding="utf-8-sig", errors="ignore"))
except FileNotFoundError:
print("File \'%s\' not found" % filePath)
sys.exit(1)