By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,018 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,018 IT Pros & Developers. It's quick & easy.

usage of __import__ across two files

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"bwobbones" <bw*******@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.