Hello,
Cody Precord wrote:
Hello,
Any idea what’s going on here?
import string
string.letters
‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’
import wx
string.letters
‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz’
Fortunately we can use string.uppercase instead in the circumstance where this was a problem, but this doesn’t seem like something that should happen. . . wxGTK 2.8.9.1 <http://2.8.9.1> with Python 2.6, by the way.
I can reproduce this as well with wxGTK 2.8.7.1 python2.5.2
But not on wxMac
Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
import string
string.letters
‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’
import wx
string.letters
‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’
Cody
Windows XP does the opposite of Mac by sticking all the uppercase at the beginning. However, it adds a bunch of extra junk at the end too:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
IDLE 1.2.2 >>> import string
string.letters
‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\x83\x8a\x8c\x8e\x9a\x9c\x9e\x9f\xaa\xb5\xba\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff’
import wx
string.letters
‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\x83\x8a\x8c\x8e\x9a\x9c\x9e\x9f\xaa\xb5\xba\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff’
Actually I think that this is caused by IDLE. If you run python from the command prompt you will get different results.
C:\Python25>python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type “help”, “copyright”, “credits” or “license” for more information.
import string
string.letters
‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’
import wx
string.letters
‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’
I’m using wxPython 2.8.9.1. Note that you can use Python’s builtin string handling functions “upper” and “lower” to work around this:
Actually this would make the issue worse as you would end up with only half of the original set of letters and have duplicates.
myString = string.letters
myString = myString.lower()
myString
‘abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\x83\xaa\xac\xae\x9a\x9c\x9e\xbf\xaa\xb5\xba\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff’
Using str.swapcase() would reverse the string back.
“ABCDEFGabcdefg”.swapcase()
‘abcdefgABCDEFG’
Though does the order of the letters in the string really matter? The only time I have ever used the the string module is to do something like the following.
if ch in string.letters:
doSomething()
It should only be treated as a set of values, the order cannot be guaranteed. It would not be safe to write code that depends on the order of set that is in code outside your control. If a new version of python decides to change the order for some reason you would end up with broken code. So it would probably be better to write using the explicit uppercase and lowercase values anyway, or just reproduce the letters string it in your code.
Though I do agree that it is very odd that importing wx changes the order of string.letters on Linux.
Cody
···
On Fri, Nov 21, 2008 at 10:03 AM, Mike Driscoll mike@pythonlibrary.org wrote:
On Nov 20, 2008, at 5:40 PM, Nathaniel Echols wrote: