Python 隐藏变量
__doc__ # 表示本文件的注释
__file__ # 表示本文件的路径
__package__ # 导入的py文件所在的文件夹路径
__cached__ # 导入文件的缓存
__name__ #如果是主文件 __name__ = "__main__" 否则等于函数名称
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
{
'__builtins__': <module 'builtins' (built-in)>,
'__package__': None,
'__cached__': None,
'__file__': 'C:/Users/Administrator/PycharmProject/MyProject/myfunc/ceshi.py',
'__doc__': None,
'__name__': '__main__',
'__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0000026EC5A58978>,
'__spec__': None}
"""
if __name__ == '__main__':
print(__file__)
print(__doc__)
print(vars())
运行结果:
C:/Users/Administrator/PycharmProject/MyProject/myfunc/ceshi.py # __file__
{ # __doc__
'__builtins__': <module 'builtins' (built-in)>,
'__package__': None,
'__cached__': None,
'__file__': 'C:/Users/Administrator/PycharmProject/MyProject/myfunc/ceshi.py',
'__doc__': None,
'__name__': '__main__',
'__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0000026EC5A58978>,
'__spec__': None}
# vars()
{'__cached__': None, '__package__': None, '__doc__': "
{
'__builtins__': <module 'builtins' (built-in)>,
'__package__': None,
'__cached__': None,
'__file__': 'C:/Users/Administrator/PycharmProject/MyProject/myfunc/ceshi.py',
'__doc__': None,
'__name__': '__main__',
'__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0000026EC5A58978>,
'__spec__': None}
", '__builtins__': <module 'builtins' (built-in)>, '__file__': 'C:/Users/Administrator/PycharmProject/MyProject/myfunc/ceshi.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x000002354BFB8978>, '__spec__': None, '__name__': '__main__'}