I have been trying to read a file in python, the thing is that it returns an empty string. 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?
CodePudding user response:
- change
f.readlines()
tofile.readlines()
This is only a typo. But I don't know why you don't get the error here. I think you open another file as f And You get the empty string here 'cause if you try to read a file more than once, you got an empty string except for the first time. - As you say the file size is
4TB
, This could be the problem because ofMax File Size In Python
CodePudding user response:
with open('data.txt') as file:
content = file.readlines()
print(content) #prints nothing
This should work i think
CodePudding user response:
You need to make sure your text file name is the proper one, but most important, you need to provide full path of the file, in case it is not in the same directory as the script.