Ruby and Python

Fredrik Lundh fredrik at effbot.org
Sun Nov 19 16:15:18 EST 2000


"graham73" wrote:
> Actually it is a big deal. When you do
>
>     c = a + b
>
> to construct the object c (say a and b are ints, although in this
> case c isn't an object, but that doesn't change me point), you don't
> have to say where you are getting a and b from (which environment or
> namespace or whatever you want to call it).  But if I want to define a
> function I do have to be explicit about where I am getting objects used
> in the function definition from.

Really?

Python uses a two-scope model.  For each name in a
function body, the compiler decides whether the name
is global or local at compile time.  Names that are bound
inside the function (the argument to the function, names
that you assign to, names you import, etc) are considered
to be local, all other names are global.

Global names belong to the module in which the function
was defined, local names belong to the local namespace
(owned by the frame).

The resulting function object is a first-class object, and
can be treated like any other value in the system.

</F>





More information about the Python-list mailing list