468,511 Members | 1,634 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,511 developers. It's quick & easy.

Python Import Statement

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)

but it gives me an error of the kind, object cannot be called?

Any hints

thank you
J.

Jul 18 '05 #1
2 32028
jinal jhaveri <jh*****@usc.edu> wrote:

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)
Python treats file names as case sensitive, so you probably want

from xyz.a import B

Do you have an __init__.py in directory xyz so Python knows it is a module?
but it gives me an error of the kind, object cannot be called?


Not from that line, it doesn't. Show us the line where you try to
instantiate it. This kind of thing should work:

from xyz.a import B
bb = B()
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2
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
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

54 posts views Thread by Brandon J. Van Every | last post: by
5 posts views Thread by John Ladasky | last post: by
8 posts views Thread by Gekitsuu | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
13 posts views Thread by John Dann | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.