getting memory usage of varaibles

Steve D'Aprano steve+python at pearwood.info
Wed May 3 20:09:48 EDT 2017


On Thu, 4 May 2017 09:30 am, Ned Batchelder wrote:

> Functions, classes, and modules can also be referred to by a number of
> variables:
> 
>     def foo(): pass
>     bar = baz = foo
> 
> But functions (by virtue of the name in the def statement) have an
> inherent name, 

Indeed; but we also have anonymous functions:

lambda arg: expression

Technically all functions created with lambda do have a __name__ attribute,
but since they're all the same, its the next best thing to anonymity.

We can even have anonymous classes and modules:

py> T = type('', (object,), {})
py> T
<class '__main__.'>

py> from types import ModuleType
py> m = ModuleType('', '')
py> m
<module ''>



-- 
Steve
Emoji: a small, fuzzy, indistinct picture used to replace a clear and
perfectly comprehensible word.




More information about the Python-list mailing list