Re: [Tutor] Filtering a String

2005-03-20 Thread Sean Perry
Matt Williams wrote: Dear List, I'm trying to filter a file, to get rid of some characters I don't want in it. I've got the "Python Cookbook", which handily seems to do what I want, but: a) doesn't quite and b) I don't understand it I'm trying to use the string.maketrans() and string.translate().

Re: [Tutor] Filtering a String

2005-03-20 Thread Archie Maskill
On Sun, 20 Mar 2005 22:05:23 +, Matt Williams <[EMAIL PROTECTED]> wrote: > I've tried: > > #!/usr/bin/python > import string > test="1,2,3,bob,%,)" > allchar=string.maketrans('','') > #This aiming to delete the % and ): > x=''.translate(test,allchar,"%,)") > > but get: > TypeError: translate

Re: [Tutor] Filtering a String

2005-03-20 Thread Jacob S.
I'm trying to filter a file, to get rid of some characters I don't want in it. The easiest thing to do is use the string method replace. For example: char = "1" a = open("Myfile.txt","r") b = a.read() a.close() b = b.replace(char,"") a = open("Myfile.txt","w") ## Notice "w" so we can replace th

[Tutor] Filtering a String

2005-03-20 Thread Matt Williams
Dear List, I'm trying to filter a file, to get rid of some characters I don't want in it. I've got the "Python Cookbook", which handily seems to do what I want, but: a) doesn't quite and b) I don't understand it I'm trying to use the string.maketrans() and string.translate(). From what I've re