What should I do if python open cannot find the file?

coldplay.xixi
Release: 2020-06-30 10:00:45
Original
7199 people have browsed it

What should I do if python open cannot find the file?

推荐教程:《python视频教程

python open找不到文件怎么办?

python open找不到文件的解决办法:

 在python和很多程序语言中"\"转义符号,要想输出\有两种方法,一是多加一个\写成\\ ,一是在字符串前加一个r,提示解释器按原始字符处理

  解决方法1代码:  

 try:     source=open('D:\eclipse-workspace\AcrSoftware\data\\filename.txt','r',encoding='utf-8')   except IOError:    print('Error:没有找到 文件或读取文件失败')
Copy after login

  解决方法2代码:   

 try:     source=open(r'D:\eclipse-workspace\AcrSoftware\data\filename.txt','r',encoding='utf-8')   except IOError:    print('Error:没有找到 文件或读取文件失败')
Copy after login

推荐相关文章:《python教程

The above is the detailed content of What should I do if python open cannot find the file?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!