[Tutor] special characters is changed in filename output? Why?

Ole Jensen learning.python at dbmail.dk
Sun Aug 29 23:16:27 CEST 2004


Inspired by Jeffs classical remark, I realised a better place to ask
this question would be a scandianvian board... And I just wanted to post
my result from there.

It seems that Windows uses different two character sets! Latin-1 for gui
interfaces and cp850 for console aplications. Logical indeed! I have
tested this shortly and it seems to work perfectly.

>>> s = raw_input().decode('cp850')
æøå.txt
>>> f = open(s, 'w')
>>> f.close()

Creates the correct filename, with no distortion.


----- Original Message ----- 
From: "Jeff Shannon"

> > [code]
> > f  = open("æøå.txt", "w")
> > f.write("test")
> > f.close()
> > [/code]
> >
> > creates a file named: ‘›†.txt (I hope it show up correctly in this
> > email)
> > If I did the exact same code in IDLE the file name would be correct
i.e.
> > æøå.txt!
>
> There seems to be a difference in how IDLE and the command-line Python
> interpreter handle locale -- this sort of thing seems to be a frequent
> problem.  The solution probably involves specifically setting locale
> somewhere in your Python-startup process.

> Unfortunately, I don't know
> enough about this to offer any more specific guidance -- I'm one of
> those lazy Americans who has little cause to deal with non-ascii
> characters... ;)
>



More information about the Tutor mailing list