os.walk the apostrophe and unicode

Peter Otten __peter__ at web.de
Sun Jun 25 04:47:18 EDT 2017


Steve D'Aprano wrote:

> On Sun, 25 Jun 2017 04:57 pm, Peter Otten wrote:

>> if everything worked correctly? Though I don't understand why the OP
>> doesn't see
>> 
>> '06 - Toddâ\x80\x99s Song (Post-Spiderland Song in Progress).flac'
>> 
>> which is the repr() that I get.
> 
> That's mojibake and is always wrong :-) 

Yes, that's my very point. 

> I'm not sure how you got that.

I took the OP's string at face value and pasted it into the interpreter:

# python 3.4
>>> '06 - Todd\xe2\x80\x99s Song (Post-Spiderland Song in Progress).flac'
'06 - Toddâ\x80\x99s Song (Post-Spiderland Song in Progress).flac'

> Something to do with an accidental decode to Latin-1?

If the above filename is the only one or one of a few that seem broken, and 
other non-ascii filenames look OK the OP's toolchain/filesystem may work 
correctly and the odd name might have been produced elsewhere, e. g. by 
copying an already messed-up freedb.org entry.

[Heureka]

However, the most likely explanation is that the filename is correct and 
that the OP is not using Python 3 as he claims but Python 2.

Yes, it took that long for me to realise ;) Python 2 is slowly sinking into 
oblivion...




More information about the Python-list mailing list