Functions

Jeremy Dillworth jwdillworth at yahoo.com
Mon Aug 18 19:16:37 CEST 2003


That depends on your view of the "right" f3 :)

In a nutshell, f1 is in the global scope.  So it's
going to search for f3 in the local (f1) scope (which
it will never find, since f1 doesn't have its own f3), and 
then in the global scope.  What function you call it 
from and whether or not that function has a local f3()
defined doesn't matter.

Here's an interactive session based on your example
which demonstrates:

Python 2.3 (#1, Aug 12 2003, 15:22:52)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f1():
...     f3()
...
>>> def f2():
...     def f3():
...             print "f2's f3 called"
...     f1()
...
>>> def f3():
...     print "global f3 called"
...
>>> def f4():
...     def f3():
...             print "f4's f3 called"
...     f1()
...
>>> f1()
global f3 called
>>> f2()
global f3 called
>>> f4()
global f3 called
>>>




--- Thor <thor__00 at yahoo.com> wrote:
> In this hypothetical case:
> 
> def f1:
>         f3:
> def f2:
>         def f3:
>                 pass
>         f1:
> def f4:
>         def f3:
>                 pass
>         f1:
> 
> would the function f1 execute the right f3 depending on from which functions
> is it called?
> -- 
> Thor -- Stockholm -- Sverige
> -- 
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list