Re: Cleaning up a string

2007-07-25 Thread MRAB
On Jul 24, 8:47 pm, James Stroud <[EMAIL PROTECTED]> wrote: > Hello all, > > I dashed off the following function to clean a string in a little > > program I wrote: > > def cleanup(astr, changes): >for f,t in changes: > atr = astr.replace(f, t) >return astr > > where changes would be a

Re: Cleaning up a string

2007-07-24 Thread James Stroud
Peter Otten wrote: > unicode.translate() supports this kind of replacement... > and re.compile(...).sub() accepts a function: Thanks Peter! -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/ma

Re: Cleaning up a string

2007-07-24 Thread Peter Otten
James Stroud wrote: > I dashed off the following function to clean a string in a little > program I wrote: > > def cleanup(astr, changes): >for f,t in changes: > atr = astr.replace(f, t) >return astr > > where changes would be a tuple, for example: > > changes = ( > (

Cleaning up a string

2007-07-24 Thread James Stroud
Hello all, I dashed off the following function to clean a string in a little program I wrote: def cleanup(astr, changes): for f,t in changes: atr = astr.replace(f, t) return astr where changes would be a tuple, for example: changes = ( ('%', '\%'), ('$',