#coding:gbk
#10_1从文件中读取数据
#10_1_1读取整个文件
with open(‘pi_digits.txt’) as file_object:
contents = file_object.read()
print(contents)
上面是我练习时候写的代码,在朋友charm中提示有两处错误,在geany中可以正常运行,pi_digits.txt和朋友文件在一个文件夹中,错误码如下:
C:\Users\cj111\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/cj111/python_work/9chapter/10_1_1file_reader.py
C:\Users\cj111\AppData\Local\Programs\Python\Python37-32\python.exe: can’t open file ‘C:/Users/cj111/python_work/9chapter/10_1_1file_reader.py’: [Errno 2] No such file or directory
Process finished with exit code 2
请大神帮我解决一下,谢谢。
本文探讨了在Python中使用with open()读取文件时遇到的常见错误,特别是在不同IDE中运行时出现的问题。通过一个具体示例,分析了错误原因,并提供了可能的解决方案。
7540

被折叠的 条评论
为什么被折叠?



