"Mark Young" <marky1...@gmail.com> wrote

Thanks everybody, I didn't know modules ran code when you imported them, I
just thought they defined the functions, etc. in them.

They do that too.
But in Python a function definition is created by running the code!

So you write

def foo():
    return 42

To define foo you need to execute those two lines of code.
The result is that you create a function object.

So when you import a moduile it runs all of the code in there, and
most of the code usually consists of function and variable definitions.
But it can be anything at all.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to