'Finding a list of all double-underscore variables?
Related: What is the common header format of Python files?
Where can I find a list of all double-underscore variables that are commonly used in Python?
In Python, variables starting and ending with double underscores are typically to store metadata or are built into the system. For example,
#!/usr/bin/env python
__author__ = 'Michael0x2a'
__license__ = 'GPL'
class Test(object):
def __init__(self):
print 'Hello World!'
if __name__ == '__main__':
t = Test()
I'm pretty certain __author__ and __license__ are pretty well known. What other double-underscore metadata variables are there? Is there a comprehensive list I can check somewhere? Can I just make up my own, or are there a bunch of ones that have become de-facto standards that I should use?
Things like __init__, __name__, and __doc__ are pretty much built into Python. Are those the only reserved double-underscore variables? Are there any more? Is there some place I can get a list?
[Edit]
I was browsing and encountered another question that linked to a mindmap of a bunch of double-underscore variables.
Solution 1:[1]
The complete list used by Python is given in the Python Language Reference section 3, "Data model". Every other one is non-standard or used by third-party modules and is documented separately.
Solution 2:[2]
when i use
dir(object)
i got these:
'__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__has
h__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__'
, '__setattr__', '__sizeof__', '__str__', '__subclasshook__'
and i think they are the dunder names every object will have in python
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ignacio Vazquez-Abrams |
| Solution 2 | atongsa |
