Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > usage of __import__ across two files

Reply
Thread Tools

usage of __import__ across two files

 
 
bwobbones
Guest
Posts: n/a
 
      12-12-2004
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
 
Reply With Quote
 
 
 
 
John Roth
Guest
Posts: n/a
 
      12-12-2004

"bwobbones" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
__import__(x) VS __import__(x, {}, {}, ['']) Phil Python 2 08-24-2009 02:58 AM
how can I replace a execfile with __import__ in class to use self variables Wensheng Python 2 02-10-2005 06:11 PM
re: usage of __import__ across two files bwobbones Python 1 12-13-2004 12:05 PM
__import__ Coder Coder Python 4 05-08-2004 09:33 AM
__import__() with packages Marco Herrn Python 5 04-06-2004 07:47 AM



Advertisments