Replacing control characters.

Erno Kuusela erno-news at erno.iki.fi
Mon Jan 22 19:12:31 EST 2001


In article <94ifec$ggt$1 at nnrp1.deja.com>, johnvert at my-deja.com writes:

| I want to remove all of these characters, but since
| it's not an actual caret (^) and a letter M, but the *Ctrl* character
| C-M I don't know how to refer to them in a regexp.  How can I?

C-M would be '\x0d'. you can look at the ascii(7) manual page
for the codes, or type something like print hex(ord('^M')) at
the prompt. the way to insert a literal ^M there is to first
type ^V to prevent readline or the tty driver from meddling with it.

| Also, what would be the most efficient way to do this in Python
| (e.g. use regexp functions to maybe module string will do?)

string.translate()/string.maketrans() probably.

  -- erno



More information about the Python-list mailing list