用python打开文件(命令打开)
我正在做一个用python编程的在线课程。我必须阅读列表中的文件内容。我写了下面的代码。这个程序可以工作,但当我把我的工作提交到网站上时,它给了我下面的信息。你知道会有什么问题吗?多谢各位用python打开文件(命令打开),python,file-io,Python,File Io,我正在做一个用python编程的在线课程。我必须阅读列表中的文件内容。我写了下面的代码。这个程序可以工作,但当我把我的工作提交到网站上时,它给了我下面的信息。你知道会有什么问题吗?多谢各位 def read_words(words_file): """ (file open for reading) -> list of str Return a list of all words (with newlines removed) from open file wor
def read_words(words_file):
""" (file open for reading) -> list of str
Return a list of all words (with newlines removed) from open file
words_file.
Precondition: Each line of the file contains a word in uppercase characters
from the standard English alphabet.
"""
words_file=open(words_file)
los=[]
for line in words_file:
if '\n' in line:
line=line[:len(line)-1]
los.append(line)
return (los)
方法说明:
没有
信息:
错误:DisabledBuiltError
不允许调用内置的open。出于安全原因,该网站不允许您调用open。如果它在您的计算机上运行,只需按原样提交即可。当然,除非出现错误消息,因为分配明确指出您不允许使用“打开”。请关闭您的文件对象!使用带有openwords_文件的上下文管理器作为words_文件:并将所有内容缩进一次,或者使用words_文件。在代码底部关闭您应该阅读向站点提交工作的规则。我可以很容易地想象,他们以某种特殊的方式向您提供输入数据,例如通过sys.stdin,但我不喜欢猜测,请阅读文档。如果课程不错,您可以在讨论论坛中寻求更具体的帮助。