Re: [Tutor] IDLE vs. Python Command Line
magnus at thinkware.se
Thu Jun 24 16:35:39 EDT 2004
> when i type:
> >>>import string
> in IDLE, i get:
> but when i do it on the Python Command Line, i get:
> is this a flaw in IDLE or the Command Line?
Maybe... I agree that it's a bit confusing. I'm not sure why they default
to different locales.
> Which is more accurate?
Both are accurate, but in different contexts. :)
> Since one of my programs uses string.letters, it is important for me to know.
As I'm sure you know, the set of letters is different in different
contexts. If you ask someone in Japan, they are likely to say that
both sequences fail to describe the letters.
If you run this...
>>> import locale
I assume you will get different results in IDLE and at the command line. At
least I do in Windows. I also get strings that are constent with the locale
settings. (Well, fairly at least, my GUI locale says 'Swedish_Sweden', '1252'
and I get all the letters in codepage 1252 as letters, but that's much more
than the Swedish letters of course...but that's how it is...)
I'm not sure why IDLE is set up to give a different default that the CLI
version, but remember the Python mottos:
Explicit is better than implicit.
In the face of ambiguity, refuse the temptation to guess.
If you depend on string.letters to return only US ASCII letters, run this:
Another option is to use string.ascii_letters instead, which is always the same.
If you want the locale setting defined by the OS, use this:
If you always set locale in your program, you won't depend on any unclear
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus at thinkware.se
More information about the Tutor