writing \feff at the begining of a file

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Aug 13 05:45:28 EDT 2010


Hello python world,

I'm trying to update the content of a $Microsoft$ VC2005 project files 
using a python application.
Since those files are XML data, I assumed I could easily do that.

My problem is that VC somehow thinks that the file is corrupted and 
update the file like the following:

-<?xml version='1.0' encoding='UTF-8'?>
+?<feff><?xml version="1.0" encoding="UTF-8"?>


Actually, <feff> is displayed in a different color by vim, telling me 
that this is some kind of special caracter code (I'm no familiar with 
such thing).
After googling that, I have a clue : could be some unicode caracter use 
to indicate something ... well I don't know in fact ("UTF-8 files 
sometimes start with a byte-order marker (BOM) to indicate that they are 
encoded in UTF-8.").

My problem is however simplier : how do I add such character at the 
begining of the file ?
I tried

f = open('paf', w)
f.write(u'\ufeff')

UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in 
position 0: ordinal not in range(128)

The error may be explicit but I have no idea how to proceed further. Any 
clue ?

JM




More information about the Python-list mailing list