Printing the name of a variable
tjreedy at udel.edu
Thu Sep 9 23:40:14 CEST 2010
On 9/9/2010 3:43 PM, Stephen Boulet wrote:
In Python, 'variable' is a synonym for name and identifier,'
An object can have 0 to many names attached to it. An object can also be
a member of 0 to many collections.
Modules, classes, and functions have 'definition name' strings attached
to them as their .__name__ attribute. This attribute is used to display
the 'value' of these objects, as in
>>> def f(): pass
<function f at 0x00F05420>
The __name__ attribute is also used in the idiom
>>> if __name__ == '__main__': print("I am the main module")
I am the main module
to determine if a module is being run as the main module as imported
into another module.
Terry Jan Reedy
More information about the Python-list