Importing from a module which contains more than one Class...
kalman_g at msn.com
Mon May 11 07:04:00 EDT 2009
> GKalman <kalma... at msn.com> 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
>> the File name is the SAME as the Class name.
>> How to import from a File which contains more than one (unrelated)
> 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 MyClass.py 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_ MyClass.py
> 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: http://www.nabble.com/Importing-from-a-module-which-contains-more-than-one-Class...-tp23476815p23481160.html
Sent from the Python - python-list mailing list archive at Nabble.com.
More information about the Python-list