https://blog.csdn.net/qq_43401808/article/details/88887356
这是一个只读的结构序列,保存并导出了启动Python时的命令行选项。
# Python 3.7.3
[tony@tony-controller bin]$ ./python3 --version
Python 3.7.3
# 不指定任何选项启动Python
# 除了-R (hash_randomization)启用之外,其他选项皆默认关闭。
[tony@tony-controller bin]$ ./python3
Python 3.7.3 (default, Apr 25 2019, 09:22:47)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.flags
sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0, dev_mode=False, utf8_mode=0)
>>> quit()
# Python启动时,指定所有选项
# -v:打印出启动时所有的import
[tony@tony-controller bin]$ ./python3 -d -i -I -O -B -s -S -E -v -b -q -R -X dev -X utf8
import _frozen_importlib # frozen
import _imp # builtin
import '_thread' #
import '_warnings' #
import '_weakref' #
# installing zipimport hook
import 'zipimport' #
# installed zipimport hook
import '_frozen_importlib_external' #
import '_io' #
import 'marshal' #
import 'posix' #
import _thread # previously loaded ('_thread')
import '_thread' #
import _weakref # previously loaded ('_weakref')
import '_weakref' #
import 'faulthandler' #
# /home/tony/python37/lib/python3.7/encodings/__pycache__/__init__.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/encodings/__init__.py
# code object from '/home/tony/python37/lib/python3.7/encodings/__pycache__/__init__.cpython-37.opt-1.pyc'
# /home/tony/python37/lib/python3.7/__pycache__/codecs.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/codecs.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/codecs.cpython-37.opt-1.pyc'
import '_codecs' #
import 'codecs' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e373898>
# /home/tony/python37/lib/python3.7/encodings/__pycache__/aliases.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/encodings/aliases.py
# code object from '/home/tony/python37/lib/python3.7/encodings/__pycache__/aliases.cpython-37.opt-1.pyc'
import 'encodings.aliases' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e38ea50>
import 'encodings' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3effd0>
# /home/tony/python37/lib/python3.7/encodings/__pycache__/utf_8.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/encodings/utf_8.py
# code object from '/home/tony/python37/lib/python3.7/encodings/__pycache__/utf_8.cpython-37.opt-1.pyc'
import 'encodings.utf_8' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3a4108>
import '_signal' #
# /home/tony/python37/lib/python3.7/encodings/__pycache__/latin_1.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/encodings/latin_1.py
# code object from '/home/tony/python37/lib/python3.7/encodings/__pycache__/latin_1.cpython-37.opt-1.pyc'
import 'encodings.latin_1' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3a8210>
# /home/tony/python37/lib/python3.7/__pycache__/io.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/io.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/io.cpython-37.opt-1.pyc'
# /home/tony/python37/lib/python3.7/__pycache__/abc.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/abc.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/abc.cpython-37.opt-1.pyc'
import '_abc' #
import 'abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3a8b58>
import 'io' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3a8580>
# /home/tony/python37/lib/python3.7/__pycache__/warnings.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/warnings.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/warnings.cpython-37.opt-1.pyc'
# /home/tony/python37/lib/python3.7/__pycache__/re.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/re.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/re.cpython-37.opt-1.pyc'
# /home/tony/python37/lib/python3.7/__pycache__/enum.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/enum.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/enum.cpython-37.opt-1.pyc'
# /home/tony/python37/lib/python3.7/__pycache__/types.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/types.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/types.cpython-37.opt-1.pyc'
import 'types' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3621b8>
import '_collections' #
import 'enum' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e348f78>
# /home/tony/python37/lib/python3.7/__pycache__/sre_compile.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/sre_compile.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/sre_compile.cpython-37.opt-1.pyc'
import '_sre' #
# /home/tony/python37/lib/python3.7/__pycache__/sre_parse.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/sre_parse.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/sre_parse.cpython-37.opt-1.pyc'
# /home/tony/python37/lib/python3.7/__pycache__/sre_constants.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/sre_constants.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/sre_constants.cpython-37.opt-1.pyc'
import 'sre_constants' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3130b0>
import 'sre_parse' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e302528>
import 'sre_compile' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e36af78>
# /home/tony/python37/lib/python3.7/__pycache__/functools.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/functools.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/functools.cpython-37.opt-1.pyc'
import '_functools' #
# /home/tony/python37/lib/python3.7/collections/__pycache__/__init__.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/collections/__init__.py
# code object from '/home/tony/python37/lib/python3.7/collections/__pycache__/__init__.cpython-37.opt-1.pyc'
# /home/tony/python37/lib/python3.7/__pycache__/_collections_abc.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/_collections_abc.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/_collections_abc.cpython-37.opt-1.pyc'
import '_collections_abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc496c39dc0>
# /home/tony/python37/lib/python3.7/__pycache__/operator.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/operator.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/operator.cpython-37.opt-1.pyc'
import '_operator' #
import 'operator' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc496c45fd0>
# /home/tony/python37/lib/python3.7/__pycache__/keyword.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/keyword.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/keyword.cpython-37.opt-1.pyc'
import 'keyword' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc496bf87e8>
# /home/tony/python37/lib/python3.7/__pycache__/heapq.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/heapq.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/heapq.cpython-37.opt-1.pyc'
# extension module '_heapq' loaded from '/home/tony/python37/lib/python3.7/lib-dynload/_heapq.cpython-37m-x86_64-linux-gnu.so'
# extension module '_heapq' executed from '/home/tony/python37/lib/python3.7/lib-dynload/_heapq.cpython-37m-x86_64-linux-gnu.so'
import '_heapq' # <_frozen_importlib_external.ExtensionFileLoader object at 0x7fc496bf7f78>
import 'heapq' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc496bf76e0>
import 'itertools' #
# /home/tony/python37/lib/python3.7/__pycache__/reprlib.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/reprlib.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/reprlib.cpython-37.opt-1.pyc'
import 'reprlib' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc496bf3e70>
import 'collections' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc496c11630>
import 'functools' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e31fc08>
import '_locale' #
# /home/tony/python37/lib/python3.7/__pycache__/copyreg.cpython-37.opt-1.pyc matches /home/tony/python37/lib/python3.7/copyreg.py
# code object from '/home/tony/python37/lib/python3.7/__pycache__/copyreg.cpython-37.opt-1.pyc'
import 'copyreg' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc4969a01b8>
import 're' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e343210>
import 'warnings' # <_frozen_importlib_external.SourceFileLoader object at 0x7fc49e3aec08>
>>> sys.flags
Traceback (most recent call last):
File "" , line 1, in <module>
NameError: name 'sys' is not defined
>>> import sys
>>> sys.flags
sys.flags(debug=1, inspect=1, interactive=1, optimize=1, dont_write_bytecode=1, no_user_site=1, no_site=1, ignore_environment=2, verbose=1, bytes_warning=1, quiet=1, hash_randomization=1, isolated=1, dev_mode=True, utf8_mode=1)
>>>