Escapes???
Mike Fletcher
mfletch at tpresence.com
Fri Jun 2 19:41:53 EDT 2000
In case you don't find some compiler switch that fixes it, here's a
simplistic mechanism that does the hex escaping (doesn't currently do the \n
etceteras, that's an exercise for the reader I suppose)... Note the use of
raw strings in the test case!
import string
def dehex( rawstring ):
set = string.split( rawstring, '\\x' )
initial = set[0]
for element in set[1:]:
initial = initial + chr(string.atoi( element[:2], 16 ))
initial = initial + element[2:]
return initial
test = r"H\x1b\x23\x12art\x1b\x23\x01\n"
print `dehex( test )`
Enjoy,
Mike
-----Original Message-----
From: kern at caltech.edu [mailto:kern at caltech.edu]
Sent: Friday, June 02, 2000 4:21 PM
To: python-list at python.org
Subject: Re: Escapes???
In article <8h8jg3$d66$1 at slb6.atl.mindspring.net>,
aahz at netcom.com (Aahz Maruch) writes:
> In article <8h87u1$sga$1 at news2atm.raleigh.ibm.com>,
> Arinté <shouldbe at message.com> wrote:
>>
>>I am trying to write this escape seq to a device from python
>>"H\x1b\x23\x12art\x1b\x23\x01\n"
>>The \x1b\x23\x12 is supposed to be a command tell the device to do
something
>>special with "art", but python is making it look like this \x1b\x23\x12a
>>"rt". Am I missing something on how to work with escape sequences? Is
>>there another way to write hex values in a string. I rather us \x00
because
>>that is what are testers are familiar with.
...
More information about the Python-list
mailing list