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.

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.

THX it helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.