writing \feff at the begining of a file
Ulrich Eckhardt
eckhardt at satorlaser.com
Fri Aug 13 06:43:44 EDT 2010
Jean-Michel Pichavant wrote:
> My problem is however simplier : how do I add such character [a BOM]
> 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)
Try the codecs module to open the file, which will then do all the
transcoding between internal texts and external UTF-8 for you.
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
More information about the Python-list
mailing list