Is an interactive command a block?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Nov 20 21:37:12 CET 2009


On Fri, 20 Nov 2009 08:02:38 -0800, Ethan Furman wrote:

>> Thanks, but hey, contradiction: you mention globals as an "enclosing"
>> scope, i.e. that a module can have a scope, while stating that only
>> classes and functions have their own scope (so, would a module have
>> it's not own scope?).
> 
> module scope == global scope
> 
> That is, there is nothing higher than module scope.  (So, yes, global is
> a slight misnomer... in Python it means 'global to a module'.)

Actually there is: built-ins.

That's why you can access (e.g.) len without having to define it, or 
import it, first. And what's more, you can do this:


>>> len([1,2,3])
3
>>> def len(x):  # Shadow the built-in
...     return -3
...
>>> len([1,2,3])
-3
>>> del len
>>> len([1,2,3])  # It's back!
3



-- 
Steven



More information about the Python-list mailing list