0

Hey so I am trying to fit the entire text of the Odyssey into a string like this

with open('odyssey.txt','r') as file:
    odysseytext = file.read().replace('\n', '')
print(odysseytext)

But when I print it out I am only getting the first 598261 characters (checked with len()) Does anyone know why this is happening or how to create a string with a very large amount of text? Thanks

tdelaney
  • 73,364
  • 6
  • 83
  • 116
Fossil
  • 1
  • 1
    looks like your file is "only" 598261 characters long. You can have as long strings as you want – Mahrkeenerh Oct 06 '21 at 20:35
  • That's about the size of it. Downloading from Gutenberg https://gutenberg.org/files/1727/1727-0.txt, I got 698563 which includes the Gutenberg wrapper text and a fairly long intro by the translator. How big is this file on disk? `print(os.stat('odyssey.txt').st_size)`? it'll be a bit less than that because you remove newlines. – tdelaney Oct 06 '21 at 20:39
  • I can't reproduce a clipped string with 1x or 10x *odyssey.txt* from project gutenberg. The size of a string should only be limited by your [RAM](https://stackoverflow.com/a/40352838/14277722). – Michael Szczesny Oct 06 '21 at 20:44
  • @Mahrkeenerh You are right that is the size of my file, I hadn't noticed that. But when I print out the txt in VScode's terminal it only prints a portion of it. Is there a limit to size of string VScode will print? – Fossil Oct 06 '21 at 20:48
  • yes, they cut the string so it doesn't start lagging. But I think there should be a button to display the whole output anyway – Mahrkeenerh Oct 06 '21 at 21:14
  • Side question: *why* are you trying to make massive strings without any separation? – 2e0byo Oct 06 '21 at 21:53

0 Answers0