parsing text from a file

Tim Golden mail at timgolden.me.uk
Fri Jan 30 03:39:43 EST 2009


Wes James wrote:
> If I read a windows registry file with a line like this:
> 
> "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program
> Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted
> Multicast|Edge=FALSE|"


Watch out. .reg files exported from the registry are typically
in UTF16. Notepad and other editors will recognise this and
display what you see above, but if you were to, say, do this:


print repr (open ("blah.reg").read ())

You might see a different picture. If that's the case, you'll
have to use the codecs module or decode the string you read.


TJG



More information about the Python-list mailing list