0

I have written the simplest python code (module) :

def newplus(x, y):
    return x*y

This is stored in a folder sabya (which is my package). The folder has _init_ and newplus.py files.

In my IDLE I can open the module sabya.newplus. When I give import sabya.newplus there is no error. but when I issue :

>>> sabya.newplus(2, 3)

I am getting this error

   Traceback (most recent call last):
  File "<pyshell#15>", line 1, in <module>
    sabya.newplus(2, 3)
TypeError: 'module' object is not callable
1
  • 1
    Note that '_init_' != '__init__'. Commented Dec 1, 2014 at 14:36

1 Answer 1

4

You need to qualify the function as follow:

sabya.newplus.newplus(2, 3)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot. It worked. I am new to Python. Today is the first I am learning Python so didn't it at all. I think the way it works is sabya is the package(directory), newplus is the module(.py file) and within it newplus is the function. so my function has to be qualified as package.module.function_name. Am I right?
Another way of importing: from sayba.newplus import newplusand then call newplus(2, 3).
Thanks a lot again. I added another function hello(str) to the newplus.py file and called sabya.newplus.hello('test). It worked. Thanks for helping me understand the concept.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.