[Edu-sig] Function Question -- I'm confused...
agauld@crosswinds.net
agauld@crosswinds.net
Mon, 17 Sep 2001 21:55:07 +0100
On 17 Sep 01, at 10:42, WHITSTON@ltu.edu wrote:
> Over the weekend I was reading a Python textbook and in the chapter on
> functions it mentioned that Python functions could have embedded functions
> like Pascal.
Since version 2 thats true. Its whats called embedded scopes
Thus you can do this:
def foo():
def bar():
print "Hello from bar"
bar()
Now calling foo will print the messsaage but if you try to
call bar() from outside foo() your get a name error.
In earlier versions of Python I think you could still type
the code but bar would still be seen at the module level.
> Thank you for your help -- you could reply to me privately unless other
> newbies are interested in this.
I would imagine newbies will be interested but you are more
likely to find them on the python-tutor mailing list rather than
edu-sig which is targetted at educators rather than students...
There's a hint there somewhere <wink>
Alan G