标签:module var 路径 运行 mod min __name__ 缓存 spec
__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__‘: "\n{\n ‘__builtins__‘: <module ‘builtins‘ (built-in)>, \n ‘__package__‘: None,\n ‘__cached__‘: None,\n ‘__file__‘: ‘C:/Users/Administrator/PycharmProject/MyProject/myfunc/ceshi.py‘, \n ‘__doc__‘: None, \n ‘__name__‘: ‘__main__‘, \n ‘__loader__‘: <_frozen_importlib_external.SourceFileLoader object at 0x0000026EC5A58978>,\n ‘__spec__‘: None}\n", ‘__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__‘}
标签:module var 路径 运行 mod min __name__ 缓存 spec
原文地址:http://www.cnblogs.com/ming5218/p/7920602.html