473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 32221
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
5
by: John Ladasky | last post by:
Hi, folks, At the beginning of 2003, I was a frustrated computer user, and lapsed programmer, with problems to solve that screamed for programming. Thanks to the Python language and community, I...
8
by: Gekitsuu | last post by:
I've been reading a lot of python modules lately to see how they work and I've stumbled across something that's sort of annoying and wanted to find out of there was a good reason behind it. In a...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 430 open ( -4) / 3447 closed (+17) / 3877 total (+13) Bugs : 922 open ( -7) / 6316 closed (+31) / 7238 total (+24) RFE : 245 open...
13
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.