[Tutor] MemoryError

Liam Clarke cyresse at gmail.com
Wed Dec 8 11:29:38 CET 2004

Hi all, 

I'm playing with a file, and attempting to replace a section with a
string, and using the following command -

codeSt=codeSt.replace(seg, hrefString)

At the replace, I get a MemoryError. It's part of a for loop, but it
gives the error the first time around.

The Python docs say - "Raised when an operation runs out of memory but
the situation may still be rescued (by deleting some objects). The
associated value is a string indicating what kind of (internal)
operation ran out of memory. Note that because of the underlying
memory management architecture (C's malloc() function), the
interpreter may not always be able to completely recover from this
situation; it nevertheless raises an exception so that a stack
traceback can be printed, in case a run-away program was the cause. "

codeSt is a loaded text file that's 228Kb in size. The for loop that
the above code is embedded in, generates a slightly new codeSt each

Now, I had imagined that codeSt=codeSt+10 would destroy the old codeSt
in memory and create a new codeSt. Am I right?

Because, even if the for loop (which will iterate 267 times) were to
keep a new copy of codeSt in memory,  it should only need 59Mb of RAM,
when I've got near half a gig of RAM and virtual memory.

So yeah, I don't know how to troubleshoot this one.

Full code is here - 


Any help that can be offered gratefully appreciated. I don't want to
to have to learn C++? Malloc has an evil reputation.

Oh, and Python 2.3.4, Windows XP Pro SP1, Athlon 650MHz, 256Mb RAM
20Gb HD, which has 1.6Gb free. In case any of that infos relevant.

: )


Liam Clarke
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.

More information about the Tutor mailing list