[forwarding to tutor, although it looks like Andrew's making some good
headway from other messages]
---------- Forwarded message ----------
Date: Wed, 24 May 2006 14:59:43 -0400
From: Andrew Robert <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Question on regular expressions
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hey Danny,
Your code put me right on track.
- From that point, I crafted the following code.
What is confusing is how to take the captured character and transform it
into a 3 digit hex value.
Do you know how that might be accomplished?
#!/usr/bin/python
import re
# Evaluate captured character as hex
def ret_hex(ch):
return chr((ord(ch) + 1 ) % 256 )
# Evaluate the value of whatever was matched
def eval_match(match):
return ret_hex(match.group(0))
# open file
file = open(r'm:\mq\mq\scripts\sigh.txt','r')
# Read each line, pass any matches on line to function for
# line in file.readlines():
for line in file:
a=re.sub('[^\w\s]',eval_match, line)
print a
- --
Thank you,
Andrew Robert
Systems Architect
Information Technologies
MFS Investment Management
Phone: 617-954-5882
E-mail: [EMAIL PROTECTED]
Linux User Number: #201204
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
iD8DBQFEdK0fDvn/4H0LjDwRAuipAKDFqOeQQkJ+WkaI+veIgC8oEn9/CQCfUfNO
xb7AT8W04B/F684i+Lw6kxw=
=5mPe
-----END PGP SIGNATURE-----
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor