How to find all Python built-in private variables such as __file__, __name__

built-in, document, private, private-members, python

Solution

The hidden attributes are sometimes referred to as magic methods (for objects) and for reference, I would check out the Python docs on the data model, which are fairly comprehensive and likely cover all of the attributes you're looking to find.

After you've learned the hidden attributes, you may know what you want to get, but hidden attributes may vary by implementation, so to abstract that away, use the inspect module:

import inspect

To get a lot of information:

inspect.getmembers(inspect) 

To get the file and a bit more information on a module:

>>> inspect.getfile(inspect)
'/usr/lib/python2.7/inspect.pyc'
>>> inspect.getmoduleinfo(inspect.getfile(inspect))
ModuleInfo(name='inspect', suffix='.pyc', mode='rb', module_type=2)

Problem

I want to know all Python built-in private variables such as `__file__`, `__name__`, and their purpose. but I don't see the document of all Python built-in private variables in www.python.org. I have know `dir` and `vars`. So, how to find them?

Original source