Resolved FileNotFoundError: [Errno 2] No such file or directory: 'Configuration info.csv'

Solved (Python reports error when reading csv file) FileNotFoundError: [Errno 2] No such file or directory: 'Configuration information.csv'











error code



A friend in the fan group wanted to use python to read the csv file, but an error occurred (at that time, he felt a lot of cold in his heart, and he came to me for help, and then he helped him solve it smoothly. By the way, I hope it can help. More friends who will not solve this bug), the error code is as follows: :

insert image description here

insert image description here





error translation



Error message translation :

File not found error: [Error 2] No such file or directory: 'configinfo.csv'





Reason for error



Reason for error :

If you do not add the previous absolute path to the file, my understanding is that the path where the program is located is used as the current path to search by default, so an error will be reported that the file cannot be found.Friends, you can choose one of the following two methods to modify the code! ! !





Solution



Workaround 1:

csv = open('./配置文件.csv','r',encoding='gbk')

Workaround 2 (use absolute path to file):

csv = open('E:\\自动备份文档\\Python\\修改配置\\修改配置.csv','r',encoding='gbk')

or:
csv = open(r'E:\自动备份文档\Python\修改配置\修改配置.csv','r',encoding='gbk')

help

This article has been included in: "Farewell to Bug" column

This column is used to record various difficult bugs encountered in study and work, as well as various problems raised by small partners in the fan group. Article format: error code + error translation + error reason + solution, including program installation, operation If you encounter other problems in the process of the program, after subscribing to the column + following the blogger, if you encounter other problems, you can privately chat to help solve them! ! !

Guess you like

Origin blog.csdn.net/yuan2019035055/article/details/126839088