ascii character - removing chars from string

Rune Strand rune.strand at gmail.com
Mon Jul 3 20:43:24 EDT 2006


bruce wrote:
> hi...
>
> i'm running into a problem where i'm seeing non-ascii chars in the parsing
> i'm doing. in looking through various docs, i can't find functions to
> remove/restrict strings to valid ascii chars.
>
> i'm assuming python has something like
>
> valid_str = strip(invalid_str)
>
> where 'strip' removes/strips out the invalid chars...
>
> any ideas/thoughts/pointers...

If you're able to define the invalid_chars, the most convenient is
probably to use the strip() method:
>>> a_string = "abcdef"
>>> invalid_chars = 'abc'
>>> a_string.strip(invalid_chars)
'def'




More information about the Python-list mailing list