我正在尝试打开一个 csv 文件并加载它,但是当它明确存在于我编写的文件路径中时,它声明找不到该文件。
代码
#Load the CSV file into CSV reader
csvfile = open("C:/Users/Sam/Desktop/big data/workspace/test.csv",'rb')
错误
Traceback (most recent call last):
File "C:/Users/Sam/Desktop/big data/workspace/yelpdatabase.py", line 16, in <module>
csvfile = open("C:/Users/Sam/Desktop/big data/workspace/test.csv",'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/Sam/Desktop/big data/workspace/test.csv'
最佳答案
像这样尝试:
csvfile = open(r"C:/Users/Sam/Desktop/big data/workspace/test.csv","rb")
确保您的文件名不是 test.csv.txt
有时 Windows 会将 .csv 作为文件名的一部分
Tested using Python 2.7.12
关于Python 打开文件,找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41112375/