Python Import Statement

Tim Roberts timr at probo.com
Sun Jun 29 01:58:47 EDT 2003


jinal jhaveri <jhaveri at 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, timr at probo.com
  Providenza & Boekelheide, Inc.




More information about the Python-list mailing list