newbie problem with str.replace

Mike Kent mrmakent at cox.net
Wed Aug 4 09:30:13 EDT 2010


On Aug 4, 9:10 am, BobAalsma <bob.aal... at aalsmacons.nl> wrote:
> I'm working on a set of scripts and I can't get a replace to work in
> the script - please help.

>                         bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)

I'm not sure what you are intending to do here, but string.replace
does not do its replacement in-place.  It returns a copy of the
original string, with the replacement done in the copy.  You are not
assigning the string returned by string.replace to anything,
therefore, it is immediately thrown away.

Secondly, and this is just a guess, but since you are doing the
string.replace inside of an os.walk loop, you appear to be trying to
do a filename change.  I hope you realize that this will in no way
change the name of the file *on disk*; it will only change it in
memory.



More information about the Python-list mailing list