[Tutor] A file containing a string of 1 billion random digits.

bob gailer bgailer at gmail.com
Sat Jul 17 14:43:38 CEST 2010

On 7/17/2010 8:01 AM, Richard D. Moores wrote:
> That's the goal of the latest version of my script at
> <http://tutoree7.pastebin.com/5XYaaNfp>. The best I've been able to do
> so far is a file with 800 million digits.
> But it seems the writing of 800 million digits is the limit for the
> amount of memory my laptop has (4 GB). So my question is, how can I do
> this differently? I'm pretty brand new to opening and writing files.
> Here, I can't write many shorter lines, because the end result I seek
> is one long string. But am I correct?

Not correct. Check this out:

f = open("c:\test.txt", "w")
print open("c:\test.txt").read()

When you say "line" I assume you mean text followed by whatever the OS defines as end-of-line or end-of-record.

To write such a line in Python you must include "\n" at the end.


Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list