bizarre wx/string conflict on Linux

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 with Python 2.6, by the way.

thanks,

Nat

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 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

···

On Nov 20, 2008, at 5:40 PM, Nathaniel Echols wrote:

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'

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:

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'

···

On Nov 20, 2008, at 5:40 PM, Nathaniel Echols wrote:

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

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:

Cody Precord wrote:

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> <http://2.8.9.1> with Python 2.6, by the way.

        I can reproduce this as well with wxGTK 2.8.7.1
        <http://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 <http://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.

Good point...I wasn't thinking when I wrote that. I almost never use the String module either since the builtin string methods do everything I need.

    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'

This is cool...not sure if I've seen that one or not...

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

Sorry for muddling things ups though,

Mike

···

On Fri, Nov 21, 2008 at 10:03 AM, Mike Driscoll > <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org>> wrote:
        On Nov 20, 2008, at 5:40 PM, Nathaniel Echols wrote:

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.

This is in fact what we did to fix it - string.uppercase is exactly what we wanted anyway, we just didn’t know about it when the original code was written. I’m more generally concerned about the fact that wxPython is messing with core Python functionality, especially since it’s obviously OS-dependent. I tend to do most of my coding on a Mac and only use Linux for testing; unfortunately, in this case I waited until the last minute to test the module that depended on string.letters. Most of the cross-platform bugs I encounter tend to be issues with lower-level libraries and C/C++ extensions, not so much with the wx stuff. . .

I couldn’t find anything in the core wxPython modules that would explain this, unfortunately.

I also don’t see the bug in the user installed MacPython 2.6, but I did find it in the system python (2.5.1, wxMac 2.8.9.0). I also found that the bug only appears if you import string before wx.

···

From: Cody Precord codyprecord@gmail.com
To: wxpython-users@lists.wxwidgets.org
Sent: Thursday, November 20, 2008 9:28:22 PM
Subject: Re: [wxpython-users] bizarre wx/string
conflict on Linux

Hello,

On Nov 20, 2008, at 5:40 PM, Nathaniel Echols wrote:

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 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

Nathaniel Echols wrote:

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.

The locale module is imported during wxPython's init so it can find out what the locale's default encoding is. IIRC the change to the string module items is happening from within the locale module as it will adapt string.letters and (possibly some others) to match the alphabet for the current locale.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!