renaming 'references' to functions can give recursive problems

Fredrik Lundh fredrik at pythonware.com
Wed Feb 16 12:54:01 EST 2005


"peter" <Peter.Vandersteegen at gmail.com> wrote
> ----------------------------------------------------------------------------
> PYTHON-CODE                   # REMARKS
> referenceA = SomeObject()     #  referenceA -> SomeObject()
>                              #       references to the memory space of
>                              #              some object
> referenceB = referenceA       #  referenceB -> SomeObject()
>                              #       is also a reference to ...
> referenceA = referenceB       #  referenceA references to SomeObject()
>
> # now for functions!
> fA = function                 #  fA references to memory space
>                              #  of a function

nope.  it refers to a function object.  function objects are no different
from ordinary objects.

> def newFA(input):             #  newFA references to a function

not yet.

>   return fA(input)           #  which holds a reference to fA.

nope.  the function does not hold a reference to fA.  fA is a global,
and will be resolved at runtime.

>                  #  Notice the important difference with objects!
>                  #  newFA holds a reference to the reference fA

no, it doesn't hold a reference to the reference.  it contains the name
"fA", and will look for that when you call it.

>                  #  When using object you reference to
>                  #  the memory space of fA!!!

you're confused.  resetting your brain and reading the documentation
again might help:

    http://docs.python.org/ref/objects.html
    http://docs.python.org/ref/naming.html

</F> 






More information about the Python-list mailing list