include in python
Chad Netzer
cnetzer at mail.arc.nasa.gov
Mon May 5 15:33:27 EDT 2003
On Mon, 2003-05-05 at 03:00, Bartek Golenko wrote:
> # prog.py
>
> from xxx import *
>
> def hello():
> print "Hello..."
>
> # xxx.py
>
> hello()
Python doesn't have a pre-processor, like C, nor does importing do a
textual substitution. Rather, Python essentially executes the code as
it parses a file and imports modules. So you need to define your
methods and functions (somehow) before using them (which is why
importing functions and classes from modules is both useful and
necessary).
So for this simple example, you could actually do it this way:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# prog.py - execute this "script" to run the application
from xxx import *
hello()
# xxx.py
def hello():
print "Hello..."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So, when you run prog.py, it compiles and aquires the function in xxx.py
and then executes it (in that order). You can scale up from there.
--
Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)
More information about the Python-list
mailing list