[Tutor] Question on regular expressions

Andrew Robert andrew.arobert at gmail.com
Thu May 25 16:12:53 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

lol..


Glutton for punishment I guess.

I tried removing the last parentheses but I then get an error that two
arguments are passed when three are expected.



Danny Yoo wrote:
> 
> 
>> for line in open(r'e:\pycode\out_test.txt','rb') :
>>    output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
>> 16))) % ord(s.group()), line))
> 
> 
> Let's add some whitespace.
> 
>     output.write(re.sub(r'([^\w\s])',
>                            lambda s: chr(
>                                           int(s.group(), 16)
>                                         )
>                                      ) % ord(s.group()), line))
> 
> I do see at least one too many parens here, so that's something you
> should look at.
> 
> But I'd also recommend writing a helper function here.  Just because you
> can do this in one line doesn't mean you have to.  *grin* It might be
> useful to change the lambda back to a helper function.
> 

- --
Thank you,
Andrew Robert
Systems Architect
Information Technologies
MFS Investment Management
Phone:   617-954-5882

E-mail:  arobert at mfs.com
Linux User Number: #201204
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFEdbtlDvn/4H0LjDwRAqg+AJ0SZY/T3kCpG+3qWX3F3yRSt73P7ACdFsZQ
LnBhWh95EfuHA+eMkz6gkF4=
=C0oN
-----END PGP SIGNATURE-----


More information about the Tutor mailing list