[英]Reading a file on python returns an empty string
I have been trying to read a file in python, the thing is that it returns an empty string.我一直在尝试在 python 中读取文件,问题是它返回一个空字符串。 Here is the code:
这是代码:
with open('data.txt') as file:
content = f.readlines()
print(content) #prints nothing
note: It's a really big file, is that a problem?注意:这是一个非常大的文件,有问题吗?
f.readlines()
to file.readlines()
This is only a typo.f.readlines()
更改为file.readlines()
这只是一个错字。 But I don't know why you don't get the error here.4TB
, This could be the problem because of Max File Size In Python
4TB
,这可能是因为Max File Size In Python
的问题
with open('data.txt') as file:
content = file.readlines()
print(content) #prints nothing
This should work i think我认为这应该可行
您需要确保您的文本文件名是正确的,但最重要的是,您需要提供文件的完整路径,以防它与脚本不在同一目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.