[Tutor] reading sequence codes in from a file

jacqueline juselius jacqueline_juselius@yahoo.com
Mon, 11 Jun 2001 23:16:46 -0700 (PDT)


Hi folks,

I have a config file which contain list of sequence
code pairs.

eg. ruleFile

rule1,\272,\377
rule2,\280,\375

I read these lines in with :

  lines = open(ruleFile).readlines()
and split the line and store the last two columns into
a list, creating a translation list of before and
after values.

 
I then read another file text file and see if I can
find any of these special characters that's in the
first column and translate them to what ever is in the
second column.

My problem is that when I read the rule File I don't
get an escape sequence but a string.

eg.

in python I can say 

a = "\272"  
print a

and I will get a funny character (a's length = 1)

but when I read the line from a file I get double
slashes  "//272",  its length being 4 instead of one. 
ie. python has taken it as a string.

My thought was that I could parse out "272" and then
someohow translate it to "/272" with a length of 1.

Does anyone know how to do this or how to read an
escape sequence in from a file and have it treated as
an escape sequence and not a string?

I tried the chr() function but that only handles the
256 ascii chars.


Thanks,

Jacqueline



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/