im a first time programmer learning python from books and so far ive learnt how to create and define functions but once ive saved them, im not sure how to call them so that i can use them. it works fine when i type in the function name but only if im in the same window that i wrote the function in. what i cant do is use IDLE to write the function, save it, and then call it in a completly new window. help, thx, toby.

oh and maybe i should mention im only 15, so if this is a really stupid question thats probably why.

9 Years
Discussion Span
Last Post by pydude94

Let me give you an example.
There are two files. The first is compute.py and has the code:

def sumup(a,b):
    return a+b

And there is your program, main.py

import compute
print compute.sumup(2,3)

The question is, how will python know where to find this compute module?

The answer is here.

So in the most simple case, if you put these two files into the same directory, you go there, and run python main.py , then it will work.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.