newbie problem with str.replace

Daniel da Silva ddasilva at umd.edu
Thu Aug 5 02:26:01 EDT 2010


Also,
               for bestandsnaam in dirs and files:
is probably not doing what you want. Use + to concatenate  lists.


Daniel


On Wed, Aug 4, 2010 at 6:30 AM, Mike Kent <mrmakent at cox.net> wrote:

> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100804/4667b819/attachment-0001.html>


More information about the Python-list mailing list