Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Mac-Can';找不到文件_Python - Fatal编程技术网

Python Mac-Can';找不到文件

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

有人为我编写了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 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)