• Python 内置变量


    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__'}
    
    
  • 相关阅读:
    min25筛学习笔记
    【模板】回滚莫队&不删除莫队
    UOJ#188. 【UR #13】Sanrd
    LOJ#572. 「LibreOJ Round #11」Misaka Network 与求和
    Product
    Lcm
    点是否在三角形内的判断
    今天学会了 在Linux下,用GCC编译C语言程序,mark下
    让你沉迷的五种设计
    搞清楚了自发光特效的制作原理,3张图,3个步骤
  • 原文地址:https://www.cnblogs.com/ming5218/p/7920602.html
Copyright © 2020-2023  润新知