usage of __import__ across two files

Discussion in 'Python' started by bwobbones, Dec 12, 2004.

  1. bwobbones

    bwobbones Guest

    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
    bwobbones, Dec 12, 2004
    #1
    1. Advertising

  2. bwobbones

    John Roth Guest

    "bwobbones" <> wrote in message
    news:...
    > 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
    John Roth, Dec 12, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marco Herrn

    __import__() with packages

    Marco Herrn, Apr 4, 2004, in forum: Python
    Replies:
    5
    Views:
    449
    Hung Jung Lu
    Apr 6, 2004
  2. Coder Coder

    __import__

    Coder Coder, May 8, 2004, in forum: Python
    Replies:
    4
    Views:
    699
    Heiko Wundram
    May 8, 2004
  3. bwobbones
    Replies:
    1
    Views:
    335
    Diez B. Roggisch
    Dec 13, 2004
  4. GenxLogic
    Replies:
    3
    Views:
    1,266
    andrewmcdonagh
    Dec 6, 2006
  5. Phil
    Replies:
    2
    Views:
    462
Loading...

Share This Page