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().
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
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
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