2021-05-21

Modules and Packages

[2]:
import sys
[4]:
sys.version
[4]:
'3.9.4 (default, Apr  6 2021, 00:00:00) \n[GCC 11.0.1 20210324 (Red Hat 11.0.1-0)]'
[8]:
try:
    sys.exit()
except SystemExit as e:
    print(e)

[10]:
type(sys)
[10]:
module
[11]:
orig_sys = sys
sys = 666
[14]:
try:
    sys.exit()
except Exception as e:
    print(e)
'int' object has no attribute 'exit'
[15]:
sys = orig_sys
sys.version
[15]:
'3.9.4 (default, Apr  6 2021, 00:00:00) \n[GCC 11.0.1 20210324 (Red Hat 11.0.1-0)]'
[16]:
from sys import version
version
[16]:
'3.9.4 (default, Apr  6 2021, 00:00:00) \n[GCC 11.0.1 20210324 (Red Hat 11.0.1-0)]'
[18]:
import sys
blah = sys
del sys
blah.version
[18]:
'3.9.4 (default, Apr  6 2021, 00:00:00) \n[GCC 11.0.1 20210324 (Red Hat 11.0.1-0)]'
[19]:
import sys as blah
blah.version
[19]:
'3.9.4 (default, Apr  6 2021, 00:00:00) \n[GCC 11.0.1 20210324 (Red Hat 11.0.1-0)]'
[21]:
# from sys import *
[24]:
import sys
dir(sys)
[24]:
['__breakpointhook__',
 '__displayhook__',
 '__doc__',
 '__excepthook__',
 '__interactivehook__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 '__stderr__',
 '__stdin__',
 '__stdout__',
 '__unraisablehook__',
 '_base_executable',
 '_clear_type_cache',
 '_current_frames',
 '_debugmallocstats',
 '_framework',
 '_getframe',
 '_git',
 '_home',
 '_xoptions',
 'abiflags',
 'addaudithook',
 'api_version',
 'argv',
 'audit',
 'base_exec_prefix',
 'base_prefix',
 'breakpointhook',
 'builtin_module_names',
 'byteorder',
 'call_tracing',
 'copyright',
 'displayhook',
 'dont_write_bytecode',
 'exc_info',
 'excepthook',
 'exec_prefix',
 'executable',
 'exit',
 'flags',
 'float_info',
 'float_repr_style',
 'get_asyncgen_hooks',
 'get_coroutine_origin_tracking_depth',
 'getallocatedblocks',
 'getdefaultencoding',
 'getdlopenflags',
 'getfilesystemencodeerrors',
 'getfilesystemencoding',
 'getprofile',
 'getrecursionlimit',
 'getrefcount',
 'getsizeof',
 'getswitchinterval',
 'gettrace',
 'hash_info',
 'hexversion',
 'implementation',
 'int_info',
 'intern',
 'is_finalizing',
 'last_traceback',
 'last_type',
 'last_value',
 'maxsize',
 'maxunicode',
 'meta_path',
 'modules',
 'path',
 'path_hooks',
 'path_importer_cache',
 'platform',
 'platlibdir',
 'prefix',
 'ps1',
 'ps2',
 'ps3',
 'pycache_prefix',
 'set_asyncgen_hooks',
 'set_coroutine_origin_tracking_depth',
 'setdlopenflags',
 'setprofile',
 'setrecursionlimit',
 'setswitchinterval',
 'settrace',
 'stderr',
 'stdin',
 'stdout',
 'thread_info',
 'unraisablehook',
 'version',
 'version_info',
 'warnoptions']