usage of __import__ across two files

B

bwobbones

Hi,

I'm having trouble making __import__ work with the two classes
attached. The PrintHello() method can't be seen in the BMTest2 class -
what am I doing wrong here?

****************************
class one - BMTest - in BMTest.py:
****************************
import wx
from traceback import print_exc

class ImportTest(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "ImportTest",
size = (666,480), style = wx.DEFAULT_FRAME_STYLE)
#tb = BMToolBar(self) # works just fine!
tb = __import__('BMTest2')
tb2.PrintHello()


class MyApp(wx.App):
def __init__(self, flag):
wx.App.__init__(self, flag)
def OnInit(self):
frame = ImportTest()
self.SetTopWindow(frame)
return True

if __name__ == '__main__':
try:
app = MyApp(False)
app.MainLoop()
except:
print print_exc()

**************************
class 2 BMTest2 - in BMTest2.py:
**************************
import wx

class BMToolBar(wx.ToolBar):
def __init__(self, parentFrame):
wx.ToolBar.__init__(self, parentFrame, -1,
style=wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT|wx.TB_TEXT)
print "*** gday ***"
self.Realize()

def PrintHello(self):
print "Hello"

Any help will be much appreciated!

Bones
 
J

John Roth

bwobbones said:
Hi,

I'm having trouble making __import__ work with the two classes attached.
The PrintHello() method can't be seen in the BMTest2 class - what am I
doing wrong here?

[snip]

tb = __import__('BMTest2')
tb2.PrintHello()

Shouldn't this be tb.PrintHello() ?

[snip]
Any help will be much appreciated!

Bones

John Roth
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top