加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python全局变量__name__(一个新手问题)

发布时间:2020-12-20 12:26:49 所属栏目:Python 来源:网络整理
导读:我第一次启动 python shell时有以下名称是什么?它们看起来不像__builtins__中的函数: dir(__name__)['__add__','__class__','__contains__','__delattr__','__doc__','__eq__','__format__','__ge__','__getattribute__','__getitem__','__getnewargs__','
我第一次启动 python shell时有以下名称是什么?它们看起来不像__builtins__中的函数:

>>> dir(__name__)

['__add__','__class__','__contains__','__delattr__','__doc__','__eq__','__format__','__ge__','__getattribute__','__getitem__','__getnewargs__','__getslice__','__gt__','__hash__','__init__','__le__','__len__','__lt__','__mod__','__mul__','__ne__','__new__','__reduce__','__reduce_ex__','__repr__','__rmod__','__rmul__','__setattr__','__sizeof__','__str__','__subclasshook__','_formatter_field_name_split','_formatter_parser','capitalize','center','count','decode','encode','endswith','expandtabs','find','format','index','isalnum','isalpha','isdigit','islower','isspace','istitle','isupper','join','ljust','lower','lstrip','partition','replace','rfind','rindex','rjust','rpartition','rsplit','rstrip','split','splitlines','startswith','strip','swapcase','title','translate','upper','zfill']

解决方法

__name__是一个字符串,它是一个字符串方法.它是模块的名称或顶层的’__main__’.因此,这个成语经常出现:

if __name__ == '__main__':
    # this file was called directly,not imported
    main()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读