parsing text from a file

John Machin sjmachin at lexicon.net
Fri Jan 30 10:21:25 CET 2009


On Jan 30, 7:39 pm, Tim Golden <m... at timgolden.me.uk> wrote:
> 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.
>

Ha! That's why it appeared to print "LAND" instead of "LANDesk" -- it
found and was printing "L\0A\0N\0D".



More information about the Python-list mailing list