Learning python file handling, beginning to open the file, the code is as follows
Open = F ( 'test_file.txt', 'R & lt', encoding = 'UTF-. 8')
the RES = f.readlines ()
Print ( 'S content read%'% the RES)
f.close ()
where given operating FileNotFoundError: [Errno 2] no such file or directory: 'test_file.txt'
means that without this file?
Later found to be due to more than a suffix
to modify the code: the file name suffix removed
Open = F ( 'test_file and', 'R & lt', encoding = 'UTF-. 8')
the RES = f.readlines ()
Print ( 'S content read%'% the RES)
f.close ()
succeeds: results are as follows
read the contents of [ '1.zyh \ n', ' 2.1995 \ n', '3.gggg']
Note: to read the file with py currently edited file in the same folder, you do not add the path, the same is not necessary to add a folder path in front of the file name
Open = F ( 'D: / zyh_test / test_file and', 'R & lt', encoding = 'UTF-. 8')
the RES = f.readlines ()
Print ( 'S content read%'% the RES)
f.close ()