Python Import Statement

Miki Tebeka tebeka at cs.bgu.ac.il
Sun Jun 29 08:26:54 CEST 2003


Hello Jinal,

> Hi I have two files
> say
> 
> a.py
> 
> b.py
> 
> 
> a.py has 3 classes
> 
> A
> B
> C
> 
> Now in b.py I want to instantiate an object of class B
> 
> so this is what I do in file b
> 
> from xyz.A import B    (xyz is the directory where A is lying and the
> paths are set accordingly)
You don't need to add the diretory name, just the module name (assuming
it's in sys.path)
import a
b = a.B()
OR
from a import B
b = B()

See also http://www.python.org/doc/current/tut/node8.html

HTH.
Miki




More information about the Python-list mailing list