Module import problems

Peter Hansen peter at engcorp.com
Sun Apr 4 22:45:19 EDT 2004


simo wrote:

> I'm having trouble accessing the imported classes though.
> 
> For example I have login.py which contains something like this:
> 
> class login(wx.Dialog):
...
> 
> Then main.py contains something like this:
> 
> import login
> 
> class MyApp(wx.App):
>     """define main wx app class"""
>     def OnInit(self):
>         login_frame = login()
> 
> The problem is, that when I run main.py, I cannot seem to import login
> as a class - I keep getting 'module' object not callable.
> 
> I tried login.login() to not call the module, but the class of the
> module, but that doesn't work either, I get 'module' object has no
> attribute 'login'. I thought login.login() would look for the def
> 'login' not the class anyway?

login.login(), based on the precise code that you showed, appears
to be the correct thing.  I'm not actually trying to understand
how your code works, mind you, just looking at it syntactically.

If that's giving you the error you say it is, something else is
amiss.  Do you "shadow" the "login" that comes from the import
statement with a function somewhere, or a method, in the class
MyApp, which you didn't show?  You should be able to use the
interactive prompt to "import login" and "login.login" without
getting any kind of "no attribute" error.  If you can do that,
clearly the problem is in the MyApp module.  Otherwise you've
got something wrong with login.py after all.

-Peter



More information about the Python-list mailing list