Importing from a module which contains more than one Class...

GKalman kalman_g at
Mon May 11 07:04:00 EDT 2009

alex23 wrote:
> GKalman <kalma... at> wrote:
>> from MyClass import *
>> from MyOtherClass import *     # error msg: no such module!
>> As I mentioned above,  the code for MyClass & MyOtherClass is in the same
>> file . This program only works with a single Class in a file. That is
>> when
>> the File name is the SAME as the Class name.
>> How to import from a File which contains more than one (unrelated)
>> Classes?
> You seem to have misunderstood how 'import' works, I strongly
> recommend re-reading the tutorial section:
> Basically, the import statement has two forms:
>    1. from <module> import <contents>
>    2. import <module>
> So your example of 'from <classname> import *' just doesn't make a lot
> of sense within Python.
> If contains two classes, MyClass and MyOtherClass, you
> should be able to import them with:
>    from MyClass import MyClass, MyOtherClass
> However, you _should_ be already getting _everything_
> contains as you're using the grab-all asterisk. Could you open a
> python shell in your Module_Class folder, type 'from MyClass import
> MyClass, MyOtherClass', and past whatever traceback you get here?
> --

Looks like I did misunderstand how 'import' works. Thanks for your help, now
it works OK.
View this message in context:
Sent from the Python - python-list mailing list archive at

More information about the Python-list mailing list