码迷,mamicode.com
首页 > 编程语言 > 详细

Python 内置变量

时间:2017-11-29 16:15:33      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:module   var   路径   运行   mod   min   __name__   缓存   spec   

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__: "\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__}

Python 内置变量

标签:module   var   路径   运行   mod   min   __name__   缓存   spec   

原文地址:http://www.cnblogs.com/ming5218/p/7920602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!