En Wed, 11 Mar 2009 12:46:05 -0200, <plsulliv...@gmail.com> escribió:

I have several functions which I would like to store in a different
directory so several programs can use them. I can't seem to find much
information about how to call a function if the function code is not
actually in the script itself.
The problem: do I have to cut and paste functions into a script or can
I store them in a directory and call them from a script in another
directory. If the latter is possible, how is this done? Thanks.

I suggest you read the Python tutorial at http://docs.python.org/tutorial
In particular, you're looking for "modules", and they're covered at http://docs.python.org/tutorial/modules.html

"""If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a script. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.

To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module."""

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to