python 如何读取文件?

f=open('message1.txt','r')Traceback(mostrecentcalllast):File"<pyshell#0>",line1,in<module>f=open('message1.txt','r')FileNotFoundError:[Errno2]Nosuchfileordirectory:'messa...  f=open('message1.txt','r')
Traceback (most recent call last):
 File "<pyshell#0>", line 1, in <module>
   f=open('message1.txt','r')
FileNotFoundError: [Errno 2] No such file or directory: 'message1.txt'

总是会出现No such file or directory

怎么打开文件阿

慕后森
浏览 995回答 1
1回答

芜湖不芜

我们需要新建一个文本文档,这个文档可以是windox自带的记事本;然后我们在其中输入一些我们想要的信息;新建好文档之后,我们需要点击另存为,把文件保存在一个你知道的地方;保存的时候,请注意保存格式,不然有可能python打不开;然后我们打开python的一个编辑器,IDLE;在编辑器中输入一下的信息就可以打开文件了;read是文件读取,seek是文件的指针重新指到最前面,close是文件关闭。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python