[Tutor] Alan Gauld's tut - namespaces

Alan Gauld ukc802591034 at btconnect.com
Thu Apr 27 01:21:37 CEST 2006


"Payal Rathod" <payal-python at scriptkitchen.com> wrote in message 
news:20060426174159.GA21428 at tranquility.scriptkitchen.com...
> In Alan's tutorial I haven't got the example of print42() even after
> reading the explanation.
> I get 110 if I use it as a function.
>
>>>> spam = 42
>>>> def print42(): print spam
> ...
>>>> spam = 110
>>>> print42()
> 110
>
> Why do you get 42 when you use it as module? I haven't understood the
> explantaion.

The problem here is that you are typing it all at the >>> prompt.
If you look closely you will notice that the code examples are in
different modules - ie different files.

The >>> prompt basically acts like all the code you type is in the
same module, namespaces are really only effectoive when you are
using multiple files/modules.

However I'll refrain from saying much more since I do think the
namespaces topic could be significantly improved if only I could
find better words and examples.

So please everyone, feel free to try to explain this idea to Payal
so that I can steal your ideas for the tutorial!!  :-)

-- 
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld









More information about the Tutor mailing list