Question on importing wxPython

S

Steven W. Orr

python-2.3.5
wx-2.6

I just bought the wxPython In Action book and I see that all the examples
say to
import wx
All of our pre-existing code was horribly doing a
from wxPython import *

I changed all the code so that it was doing an import wx and found that
everything was broken. In particular, references to wxNewId would fail.

634 > python
Python 2.3.5 (#2, May 4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):

In fact, the *only* way to get it was to go back to
import wxPython
and then refer to it as wxPython.wx.wxNewId

Is my system broken or am I missing something? i.e., should I be able to
say import wx?

TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
 
M

Mike Driscoll

python-2.3.5
wx-2.6

I just bought the wxPython In Action book and I see that all the examples
say to
import wx
All of our pre-existing code was horribly doing a
from wxPython import *

I changed all the code so that it was doing an import wx and found that
everything was broken. In particular, references to wxNewId would fail.

634 > python
Python 2.3.5 (#2, May 4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'wxNewId'



In fact, the *only* way to get it was to go back to
import wxPython
and then refer to it as wxPython.wx.wxNewId

Is my system broken or am I missing something? i.e., should I be able to
say import wx?

TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net

I think the issue is that you are using the old style of wxPython. The
new style is wx.Something, so in this case, you want wx.NewId(). See
sample code below:

import wx
new_id = wx.NewId()

This helps the developer know what library that function comes from. I
see you are using 2.6. Just so you know, 2.8 is out now...you may want
to upgrade. Also, there's a really nice wxPython community mailing
list you can join, which you'll find here: http://wxpython.org/maillist.php

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top