猿问

Python打开文件

我目前正在以python语言建立一个项目,该项目可以打开文本文档(.txt)。但是我遇到了一个问题。我尝试使用以下代码打开文档:


f = open("music_data.txt","r")

print(f)

但这不起作用。它只是说:


<_io.TextIOWrapper name='music_data.txt' mode='r' encoding='cp1252'>

这似乎是打印包含文档的变量的标准方法,但是随后给出了错误消息:


Traceback (most recent call last):

File "\\bcs\StudentRedir2010$\StudentFiles\MyName\MyDocuments\Computing\Programming\Python\Music Program\program.py", line 45, in <module>

mode()

File "\\bcs\StudentRedir2010$\StudentFiles\MyName\MyDocuments\Computing\Programming\Python\Music Program\program.py", line 43, in mode

mode()

TypeError: 'str' object is not callable

而且我不知道为什么会这样。


米脂
浏览 610回答 3
3回答
随时随地看视频慕课网APP

相关分类

Python
我要回答