[Tutor] calling user defined function

Lie Ryan lie.1296 at gmail.com
Wed Feb 25 05:07:11 CET 2009


On Sun, 22 Feb 2009 22:21:22 +0100, roberto wrote:

> hello
> i have a question which i didn't solved yet: i can define a function
> using the text editor provided by IDLE 3.0; then i'd like to call this
> function from the python prompt
> 
> but when i try to do it, python warns me that function doesn't exist of
> course if i define the function directly using the >>> prompt, after
> that everything is fine
> 
> may you tell me where i have to save the file that defines the function
> is order to use it later ?
> is it a problem of path ?
> 
> my version of python is 3.0, OS windows xp
> 
> thank you very much in advance

or you can also run your module with -i (interactive) argument, which 
means to put you into the interactive mode after the module ends.

# mycode.py
def foo(): 
    print 'bar'
print 'output of program (if any)'

# then run this in your shell:
$ python -i mycode.py
output of program (if any)
>>> foo()
bar



More information about the Tutor mailing list