我试图在pycharm中写一些非常琐碎的东西。
问题:
sourceText = ""
with open("lang.txt", "rt") as sourceFile:
sourceText = sourceFile.readall()
print sourceText
当我输入“。” 在“ sourceFile”之后,我得到的弹出窗口为我提供了“ readall()”方法。但是,当我尝试运行脚本时,我得到了“
Traceback (most recent call last):
....languages/languages.py", line 4, in <module>
sourceText = sourceFile.readall()
AttributeError: 'file' object has no attribute 'readall'
该方法已记录(我弹出窗口,可以使用Ctrl + Q获取此方法的文档),但似乎无法访问。
我有点困惑。
我想:
建议?
我正在使用Windows 7 64位,并且有两个python 2.7.9安装(32位和64位),其中64位位于路径1st中。Pycharm是4.0.5社区版。
您readall
为该io
模块记录的信息是正确的,但它抱怨file
,其中没有该方法。您希望该read()
方法以大块的形式读取文件中的所有数据。您也可以使用readlines()
返回列表的方法。我有PyCharm的Pro 3.4版,但它没有这样做。我会将其作为错误报告给PyCharm。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句