[Tutor] name shortening in a csv module output

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Apr 23 23:08:05 CEST 2015


On 23/04/2015 19:14, Jim Mooney wrote:
>>
>> By relying on the default when you read it, you're making an unspoken
>> assumption about the encoding of the file.
>>
>> --
>> DaveA
>
>
> So is there any way to sniff the encoding, including the BOM (which appears
> to be used or not used randomly for utf-8), so you can then use the proper
> encoding, or do you wander in the wilderness? I was going to use encoding =
> utf-8 as a suggested default. I noticed it got rid of the bom symbols but
> left an extra blank space at the beginning of the stream. Most books leave
> unicode to the very end, if they mention the BOM at all (mine is at page
> 977, which is still a bit off ;')
>

I'm hardly an expert in the encoding field but I've heard this 
https://pypi.python.org/pypi/chardet is highly recommended.

Slight aside, why a BOM, all I ever think of is Inspector Clouseau? :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list