Importing class from another file

Tobias M. tm at
Wed Jan 23 10:53:21 CET 2013


Kevin Holleran wrote:
> Traceback (most recent call last):
>   File "", line 1, in <module>
>     from Sub_Dir.My_Class import *
> ImportError: No module named Sub_Dir.My_Class
Make sure, the script you execute by passing it to the python
interpreter is in the parent directory of Sub_Dir.
Additionaly put an empty file called (double underscores!)
in Sub_Dir if you don't already have.  This is necessary to use Sub_Dir
as a package and import modules from it.

For more details see:

> I have played around a bit with the calls (removing the My_Class in
> the q_api assignment to instantiate the object, etc).
When using "from...import" on the module that contains the class, you
can use the class without the package identifier:
q_api = My_Class_Connector(string1,string2)

For your information: I think beginner questions like this one should be
asked on the tutor list:

More information about the Python-list mailing list