Python运行时服务¶
本章里描述的模块提供了和Python解释器及其环境交互相关的广泛服务。以下是综述:
sys
--- 系统相关的形参和函数abiflags
addaudithook()
argv
audit()
base_exec_prefix
base_prefix
byteorder
builtin_module_names
call_tracing()
copyright
_clear_type_cache()
_current_frames()
_current_exceptions()
breakpointhook()
_debugmallocstats()
dllhandle
displayhook()
dont_write_bytecode
_emscripten_info
pycache_prefix
excepthook()
__breakpointhook__
__displayhook__
__excepthook__
__unraisablehook__
exception()
exc_info()
exec_prefix
executable
exit()
flags
flags.debug
flags.inspect
flags.interactive
flags.isolated
flags.optimize
flags.dont_write_bytecode
flags.no_user_site
flags.no_site
flags.ignore_environment
flags.verbose
flags.bytes_warning
flags.quiet
flags.hash_randomization
flags.dev_mode
flags.utf8_mode
flags.safe_path
flags.int_max_str_digits
flags.warn_default_encoding
float_info
float_repr_style
getallocatedblocks()
getunicodeinternedsize()
getandroidapilevel()
getdefaultencoding()
getdlopenflags()
getfilesystemencoding()
getfilesystemencodeerrors()
get_int_max_str_digits()
getrefcount()
getrecursionlimit()
getsizeof()
getswitchinterval()
_getframe()
_getframemodulename()
getprofile()
gettrace()
getwindowsversion()
get_asyncgen_hooks()
get_coroutine_origin_tracking_depth()
hash_info
hexversion
implementation
int_info
__interactivehook__
intern()
is_finalizing()
last_exc
last_type
last_value
last_traceback
maxsize
maxunicode
meta_path
modules
orig_argv
path
path_hooks
path_importer_cache
platform
platlibdir
prefix
ps1
ps2
setdlopenflags()
set_int_max_str_digits()
setprofile()
setrecursionlimit()
setswitchinterval()
settrace()
set_asyncgen_hooks()
set_coroutine_origin_tracking_depth()
activate_stack_trampoline()
deactivate_stack_trampoline()
is_stack_trampoline_active()
_enablelegacywindowsfsencoding()
stdin
stdout
stderr
__stdin__
__stdout__
__stderr__
stdlib_module_names
thread_info
tracebacklimit
unraisablehook()
version
api_version
version_info
warnoptions
winver
_xoptions
sys.monitoring
--- Execution event monitoringsysconfig
—— 提供对 Python 配置信息的访问支持builtins
--- 内建对象__main__
--- 最高层级代码环境warnings
—— 警告信息的控制dataclasses
--- 数据类contextlib
--- 为with
语句上下文提供的工具abc
--- 抽象基类atexit
--- 退出处理器traceback
—— 打印或读取堆栈的跟踪信息print_tb()
print_exception()
print_exc()
print_last()
print_stack()
extract_tb()
extract_stack()
format_list()
format_exception_only()
format_exception()
format_exc()
format_tb()
format_stack()
clear_frames()
walk_stack()
walk_tb()
TracebackException
对象TracebackException
TracebackException.__cause__
TracebackException.__context__
TracebackException.exceptions
TracebackException.__suppress_context__
TracebackException.__notes__
TracebackException.stack
TracebackException.exc_type
TracebackException.exc_type_str
TracebackException.filename
TracebackException.lineno
TracebackException.end_lineno
TracebackException.text
TracebackException.offset
TracebackException.end_offset
TracebackException.msg
TracebackException.from_exception()
TracebackException.print()
TracebackException.format()
TracebackException.format_exception_only()
StackSummary
对象FrameSummary
对象- 回溯示例
__future__
--- Future 语句定义gc
--- 垃圾回收器接口enable()
disable()
isenabled()
collect()
set_debug()
get_debug()
get_objects()
get_stats()
set_threshold()
get_count()
get_threshold()
get_referrers()
get_referents()
is_tracked()
is_finalized()
freeze()
unfreeze()
get_freeze_count()
garbage
callbacks
DEBUG_STATS
DEBUG_COLLECTABLE
DEBUG_UNCOLLECTABLE
DEBUG_SAVEALL
DEBUG_LEAK
inspect
--- 检查对象- 类型和成员
getmembers()
getmembers_static()
getmodulename()
ismodule()
isclass()
ismethod()
isfunction()
isgeneratorfunction()
isgenerator()
iscoroutinefunction()
markcoroutinefunction()
iscoroutine()
isawaitable()
isasyncgenfunction()
isasyncgen()
istraceback()
isframe()
iscode()
isbuiltin()
ismethodwrapper()
isroutine()
isabstract()
ismethoddescriptor()
isdatadescriptor()
isgetsetdescriptor()
ismemberdescriptor()
- 获取源代码
- 使用 Signature 对象对可调用对象进行内省
- 类与函数
- 解释器栈
- 静态地获取属性
- 生成器、协程和异步生成器的当前状态
- 代码对象位标志
- 缓冲区旗标
BufferFlags
BufferFlags.SIMPLE
BufferFlags.WRITABLE
BufferFlags.FORMAT
BufferFlags.ND
BufferFlags.STRIDES
BufferFlags.C_CONTIGUOUS
BufferFlags.F_CONTIGUOUS
BufferFlags.ANY_CONTIGUOUS
BufferFlags.INDIRECT
BufferFlags.CONTIG
BufferFlags.CONTIG_RO
BufferFlags.STRIDED
BufferFlags.STRIDED_RO
BufferFlags.RECORDS
BufferFlags.RECORDS_RO
BufferFlags.FULL
BufferFlags.FULL_RO
BufferFlags.READ
BufferFlags.WRITE
- 命令行界面
- 类型和成员
site
—— 指定域的配置钩子