0

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?

Kelly Bundy
  • 23,480
  • 7
  • 29
  • 65

3 Answers3

2
  1. change f.readlines() to file.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.
  2. As you say the file size is 4TB, This could be the problem because of Max File Size In Python
codester_09
  • 5,622
  • 2
  • 5
  • 27
0

with open('data.txt') as file:
    content = file.readlines()
    print(content) #prints nothing


This should work i think

  • it still dosent work – sheepminecraft Jun 05 '22 at 17:39
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 05 '22 at 20:36
0

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.

  • It is in the same directory. I wonder whats the problem :( – sheepminecraft Jun 05 '22 at 17:45
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 05 '22 at 23:13