[Tutor] MemoryError

Michael Janssen mi.janssen at gmail.com
Wed Dec 8 14:41:56 CET 2004


[forgot to cc to the list]


---------- Forwarded message ----------
From: Michael Janssen <mi.janssen at gmail.com>
Date: Wed, 8 Dec 2004 14:40:46 +0100
Subject: Re: [Tutor] MemoryError
To: Liam Clarke <cyresse at gmail.com>


On Wed, 8 Dec 2004 23:29:38 +1300, Liam Clarke <cyresse at gmail.com> wrote:

> I'm playing with a file, and attempting to replace a section with a
> string, and using the following command -
>
> seg=codeSt[element:endInd+len(endStr]
> 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.

Hello Liam,

You might try to narrow the code in where the error happen. Read the
file and replace a dummy-seq-string and see what happens. Does this
work:

"test string".replace("st st", "?")

When it works, what is bad with your file? Consider asking
comp.lang.python for a greater audience.

BTW: some time past the base64 module (base64 is a mail attachment
encoding) has a bug leading to a MemoryError when undecoding an empty
base64 string. Any free GB of ram did not help.

You can allways work arround the replace:

new = old[:start] + relace_string + old[end:]

which is ugly but perhaps makes your script running.

regards
Michael


More information about the Tutor mailing list