Python的builtins模块
来源:互联网 发布:tmt行业知乎 编辑:程序博客网 时间:2024/06/02 05:43
关键字
from keyword import kwlistprint(kwlist)
于是得到了长度为33的list:
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
搞明白了这些关键字,就算了解了Python的基础语法。
关于help
在交互界面里输入help会出现“
Type help() for interactive help, or help(object) for help about object.“。
help是啥?
help定义于模块builtins中,是class _sitebuiltins._Helper的实例,通过这样的语句定义出来的:
# in builtinsfrom _sitebuiltins import _Helperhelp=_Helper()
Python解释器启动时会自动执行:
from builtins import *
你可以自己定义一个帮助实例:
from _sitebuiltins import _HelperH=_Helper()
此时H和help的效果完全一样。
_sitebuiltins模块位于C:\Python34\Lib_sitebuiltins.py中,在这个文件里就可以找到_Helper的定义:
class _Helper(object): """Define the builtin 'help'. This is a wrapper around pydoc.help that provides a helpful message when 'help' is typed at the Python interactive prompt. Calling help() at the Python prompt starts an interactive help session. Calling help(thing) prints help for the python object 'thing'. """ def __repr__(self): return "Type help() for interactive help, " \ "or help(object) for help about object." def __call__(self, *args, **kwds): import pydoc return pydoc.help(*args, **kwds)
help其实是pydoc.help的封装。
基本上所有的疑问都能在help里找到答案。 help('modules')
可获得已安装的模块。
builtins模块
dir()函数接受模块名作为参数,返回一个排好序的字符串列表,内容是一个模块里定义过的名字。比如:
import builtinsdir(builtins)
便获得了内建模块里定义的名字:
既然内建,自然是最常用或与语言概念完整性有关。
这个list的长度是150,然而不知道为啥,居然还有一个名字是'_'
,而在py源文件中打印出来list里却没有'_'
,还剩149个。然后我对这149个名字分分类:
7个模块相关
'__build_class__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__'
4个特殊名字
欢迎界面里的copyright,credits,help,license:
help前面说过了,剩下的3个则是_sitebuiltins._Printer的实例,用来打印一些信息。
6个内建常数
'True', 'False', 'None', 'Ellipsis', '__debug__', 'NotImplemented'
68个内建函数
https://docs.python.org/3/library/functions.html
61+3个异常
https://docs.python.org/3/library/exceptions.html#exception-hierarchy
- Python的builtins模块
- Python源码学习(四)-builtins模块的初始化
- Python中builtins.py文件的注解
- python之常用builtins
- v8中builtins的初始化
- 详细介绍 Python-__builtin__与__builtins__和builtins的区别与关系
- python语法31[keywords+builtins+modules]
- __builtin__、__builtins__和builtins的那些事
- [python错误]builtins.AttributeError: 'module' object has no attribute 'request'
- builtins.ValueError: could not convert string to float:的问题
- python的htmllib模块,
- python 的配置文件模块
- python的_threading_local模块
- Python有用的模块
- 常用的python模块
- python的re模块
- 常用的python模块
- Python的struct模块
- EA使用教程的笔记
- Linux Command To Find the System Configuration And Hardware Information
- 2015年终总结—愿得菩提,心似琉璃
- 自学QT之QApplication类和<qapplication.h>头文件
- JS-案例-Checkbox全选
- Python的builtins模块
- C# 与C++的区别小结
- Regionals 2014 >> North America - Greater NY >> 7097 - Growing Rectangular Spiral
- ICPC 6823 Counting substhreengs
- PHP开发app接口(1)
- java中的线程同步问题解决方案
- 动物园查找最短路径题
- Regionals 2014 >> North America - Greater NY >> 7094 - Happy Happy Prime Prime
- Eclipse Debug的一些用法