Hi,
I'm writing a program that exports keys from the registry using regedit, parses out some relevant entries, and puts them in another file ready for import at a later date. Regedit appears to export in Unicode 'utf-16' encoding, since I can read the file with the following code:
import codecs
fileOut = codecs.open(strFile, 'wb', 'utf-16')
In particular, this encoding seems to require the first two bytes of the file to be 0xFF 0xFE (saving a file in unicode from notepad produces similar results). I'm unsure over two points:
1) If I write multiple strings to the file
e.g. fileOut.write ("Foo")
fileOut.write ("Bar")
each string is written with 0xFF 0xFE infront of it("0xFF 0xFE Foo 0xFF 0xFE Bar" - spaces included for readability). I had assumed (incorrectly ?) that this was only required at the front of the file
2) To get around this problem, I made use of the fact that using python code to read the file is based on the same logic, and strips out extraneous 0xFF 0xFE sequences. E.g.
fileIn = codecs.open (strFile, 'rb', 'utf-16')
strTheLot = fileIn.read()
This gets rid of the unwanted characters, and I can now write the string out as one long entry to the file, producing one 0xFF 0xFE sequence at the top of the file, as desired. However, for some reason that I cannot fathom, somewhere near the very end of the string which I am now writing ("strTheLot" above) there are 11 NULL unicode characters (or 22 NULL bytes) written in so that it looks something like this:
".lots of string characters \some\path\info \some\more\pa00000000000th\info" where the 0 is actually a NULL byte.
Any help as to whether 1) should be happening, and why 2) is happening and how to solve it is greatly appreciated.
Thanks,
mE
P.S. My setup info:
I've installed ActiveState Python 2.1.3 Build 214, built the debug version for Windows using VC6 (SP5) which I'm using as my installation, and running under Windows 2000 SP2.
-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely
for the intended addressee(s). Unauthorised reproduction, disclosure,
modification, and/or distribution of this email may be unlawful. If you
have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message
do not necessarily reflect those of
LIFFE Holdings Plc or any of its subsidiary companies.
-----------------------------------------------------------------------