参考:http://blog.jobbole.com/55327/

http://blog.jobbole.com/56300/

http://blog.jobbole.com/56761/

1. 在交互式命令行中执行命令的内部过程

  1. 当你敲下return键的时候,python完成了以下四步:词法分析、句法分析、编译、解释。词法分析的工作就是将你刚才输入的那行代码分解为一些符号token(译者注:包括标示符,关键字,数字, 操作符等)。句法分析程序再接收这些符号,并用一种结构来展现它们之间的关系(在这种情况下使用的抽象语法树)。然后编译器接收这棵抽象语法树,并将它转化为一个(或多个)代码对象。最后,解释器逐个接收这些代码对象,并执行它们所代表的代码。

每一行我们输入的命令,都要经过上面的四个步骤,才能够被执行。

2. 函数对象

对象是面向对象理论中的基本元素,在一些动态或者解释性语言中,函数也可以看作是一种对象,比如在JavaScript,以及功能性编程语言Haskell/Ocaml中,函数都是一种特殊的对象。

函数是对象,就意味着函数可以像对象一样被执行各种操作,比如分配,释放,复制,赋值......

“函数是最好的对象”说明函数是一种对象。它就如同一个列表或者举个例子来说 :MyObject 就是一个对象。既然 foo 是一个对象,那么我们就能在不调用它的情况下使用它(也就是说,foo 和 foo() 是大相径庭的)。我们能够将 foo 当作一个参数传递给另一个函数或者赋值给一个新函数名( other_function = foo )。有了如此棒的函数,一切皆为可能!

另外,函数作为对象出现的时候,就是和函数调用有区别的,函数调用是一个动态的过程;而函数作为一个对象,是一个静态的实体概念,意思是你可以对这个对象施予一些操作,这与这个对象的类型有关,或者以面向对象的思想来说,你可以执行这个对象提供的各种接口操作(函数)。

既然是对象,那么函数对象有哪些成员呢?

  1. >>> dir
  2. <built-in function dir>
  3. >>> dir(dir)
  4. ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
  5. >>> dir(dir.func_code)
  6.  
  7. Traceback (most recent call last):
  8. File "<pyshell#2>", line 1, in <module>
  9. dir(dir.func_code)
  10. AttributeError: 'builtin_function_or_method' object has no attribute 'func_code'
  11. >>> def foo(a):
  12. x = 3
  13. return x + a
  14.  
  15. >>> foo
  16. <function foo at 0x0000000002E8F128>
  17. >>> dir(foo)
  18. ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']
  19. >>>

其中,内置函数dir的功能描述如下:

dir([object])

Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.

If the object has a method named __dir__(), this method will be called and must return the list of attributes. This allows objects that implement a custom __getattr__() or __getattribute__() function to customize the way dir() reports their attributes.

If the object does not provide __dir__(), the function tries its best to gather information from the object’s __dict__ attribute, if defined, and from its type object. The resulting list is not necessarily complete, and may be inaccurate when the object has a custom __getattr__().

The default dir() mechanism behaves differently with different types of objects, as it attempts to produce the most relevant, rather than complete, information:

  • If the object is a module object, the list contains the names of the module’s attributes.
  • If the object is a type or class object, the list contains the names of its attributes, and recursively of the attributes of its bases.
  • Otherwise, the list contains the object’s attributes’ names, the names of its class’s attributes, and recursively of the attributes of its class’s base classes.

The resulting list is sorted alphabetically.

  

除此之外,help内置函数也很重要,可以查看内置函数的帮助内容。

首先,查看当前Python程序加载了哪些模块

  1. >>> for i in sys.modules.keys():
  2. ... print "%20s:\t%s\n" % (i, sys.modules[i])
  3. ... print "*"*100
  1. copy_reg: <module 'copy_reg' from '/usr/lib/python2.7/copy_reg.pyc'>
  2.  
  3. ****************************************************************************************************
  4. sre_compile: <module 'sre_compile' from '/usr/lib/python2.7/sre_compile.pyc'>
  5.  
  6. ****************************************************************************************************
  7. _sre: <module '_sre' (built-in)>
  8.  
  9. ****************************************************************************************************
  10. encodings: <module 'encodings' from '/usr/lib/python2.7/encodings/__init__.pyc'>
  11.  
  12. ****************************************************************************************************
  13. site: <module 'site' from '/usr/lib/python2.7/site.pyc'>
  14.  
  15. ****************************************************************************************************
  16. __builtin__: <module '__builtin__' (built-in)>
  17.  
  18. ****************************************************************************************************
  19. sysconfig: <module 'sysconfig' from '/usr/lib/python2.7/sysconfig.pyc'>
  20.  
  21. ****************************************************************************************************
  22. __main__: <module '__main__' (built-in)>
  23.  
  24. ****************************************************************************************************
  25. encodings.encodings: None
  26.  
  27. ****************************************************************************************************
  28. abc: <module 'abc' from '/usr/lib/python2.7/abc.pyc'>
  29.  
  30. ****************************************************************************************************
  31. posixpath: <module 'posixpath' from '/usr/lib/python2.7/posixpath.pyc'>
  32.  
  33. ****************************************************************************************************
  34. _weakrefset: <module '_weakrefset' from '/usr/lib/python2.7/_weakrefset.pyc'>
  35.  
  36. ****************************************************************************************************
  37. errno: <module 'errno' (built-in)>
  38.  
  39. ****************************************************************************************************
  40. encodings.codecs: None
  41.  
  42. ****************************************************************************************************
  43. sre_constants: <module 'sre_constants' from '/usr/lib/python2.7/sre_constants.pyc'>
  44.  
  45. ****************************************************************************************************
  46. re: <module 're' from '/usr/lib/python2.7/re.pyc'>
  47.  
  48. ****************************************************************************************************
  49. _abcoll: <module '_abcoll' from '/usr/lib/python2.7/_abcoll.pyc'>
  50.  
  51. ****************************************************************************************************
  52. types: <module 'types' from '/usr/lib/python2.7/types.pyc'>
  53.  
  54. ****************************************************************************************************
  55. _codecs: <module '_codecs' (built-in)>
  56.  
  57. ****************************************************************************************************
  58. encodings.__builtin__: None
  59.  
  60. ****************************************************************************************************
  61. _warnings: <module '_warnings' (built-in)>
  62.  
  63. ****************************************************************************************************
  64. genericpath: <module 'genericpath' from '/usr/lib/python2.7/genericpath.pyc'>
  65.  
  66. ****************************************************************************************************
  67. stat: <module 'stat' from '/usr/lib/python2.7/stat.pyc'>
  68.  
  69. ****************************************************************************************************
  70. zipimport: <module 'zipimport' (built-in)>
  71.  
  72. ****************************************************************************************************
  73. _sysconfigdata: <module '_sysconfigdata' from '/usr/lib/python2.7/_sysconfigdata.pyc'>
  74.  
  75. ****************************************************************************************************
  76. warnings: <module 'warnings' from '/usr/lib/python2.7/warnings.pyc'>
  77.  
  78. ****************************************************************************************************
  79. UserDict: <module 'UserDict' from '/usr/lib/python2.7/UserDict.pyc'>
  80.  
  81. ****************************************************************************************************
  82. encodings.utf_8: <module 'encodings.utf_8' from '/usr/lib/python2.7/encodings/utf_8.pyc'>
  83.  
  84. ****************************************************************************************************
  85. sys: <module 'sys' (built-in)>
  86.  
  87. ****************************************************************************************************
  88. codecs: <module 'codecs' from '/usr/lib/python2.7/codecs.pyc'>
  89.  
  90. ****************************************************************************************************
  91. readline: <module 'readline' from '/usr/lib/python2.7/lib-dynload/readline.i386-linux-gnu.so'>
  92.  
  93. ****************************************************************************************************
  94. _sysconfigdata_nd: <module '_sysconfigdata_nd' from '/usr/lib/python2.7/plat-i386-linux-gnu/_sysconfigdata_nd.pyc'>
  95.  
  96. ****************************************************************************************************
  97. os.path: <module 'posixpath' from '/usr/lib/python2.7/posixpath.pyc'>
  98.  
  99. ****************************************************************************************************
  100. sitecustomize: <module 'sitecustomize' from '/usr/lib/python2.7/sitecustomize.pyc'>
  101.  
  102. ****************************************************************************************************
  103. signal: <module 'signal' (built-in)>
  104.  
  105. ****************************************************************************************************
  106. traceback: <module 'traceback' from '/usr/lib/python2.7/traceback.pyc'>
  107.  
  108. ****************************************************************************************************
  109. linecache: <module 'linecache' from '/usr/lib/python2.7/linecache.pyc'>
  110.  
  111. ****************************************************************************************************
  112. posix: <module 'posix' (built-in)>
  113.  
  114. ****************************************************************************************************
  115. encodings.aliases: <module 'encodings.aliases' from '/usr/lib/python2.7/encodings/aliases.pyc'>
  116.  
  117. ****************************************************************************************************
  118. exceptions: <module 'exceptions' (built-in)>
  119.  
  120. ****************************************************************************************************
  121. sre_parse: <module 'sre_parse' from '/usr/lib/python2.7/sre_parse.pyc'>
  122.  
  123. ****************************************************************************************************
  124. os: <module 'os' from '/usr/lib/python2.7/os.pyc'>
  125.  
  126. ****************************************************************************************************
  127. _weakref: <module '_weakref' (built-in)>
  128.  
  129. ****************************************************************************************************

  

可以通过下面代码查看__builtin__模块中的成员

  1. >>> num = 0
  2. >>> for i in dir(sys.modules["__builtin__"]):
  3. ... print "%20s\t" % i,
  4. ... num += 1
  5. ... if num == 5:
  6. ... print ""
  7. ... num = 0
  8. ...
  9. ArithmeticError AssertionError AttributeError BaseException BufferError
  10. BytesWarning DeprecationWarning EOFError Ellipsis EnvironmentError
  11. Exception False FloatingPointError FutureWarning GeneratorExit
  12. IOError ImportError ImportWarning IndentationError IndexError
  13. KeyError KeyboardInterrupt LookupError MemoryError NameError
  14. None NotImplemented NotImplementedError OSError OverflowError
  15. PendingDeprecationWarning ReferenceError RuntimeError RuntimeWarning StandardError
  16. StopIteration SyntaxError SyntaxWarning SystemError SystemExit
  17. TabError True TypeError UnboundLocalError UnicodeDecodeError
  18. UnicodeEncodeError UnicodeError UnicodeTranslateError UnicodeWarning UserWarning
  19. ValueError Warning ZeroDivisionError _ __debug__
  20. __doc__ __import__ __name__ __package__ abs
  21. all any apply basestring bin
  22. bool buffer bytearray bytes callable
  23. chr classmethod cmp coerce compile
  24. complex copyright credits delattr dict
  25. dir divmod enumerate eval execfile
  26. exit file filter float format
  27. frozenset getattr globals hasattr hash
  28. help hex id input int
  29. intern isinstance issubclass iter len
  30. license list locals long map
  31. max memoryview min next object
  32. oct open ord pow print
  33. property quit range raw_input reduce
  34. reload repr reversed round set
  35. setattr slice sorted staticmethod str
  36. sum super tuple type unichr
  37. unicode vars xrange zip >>>

  

  

3. dir内置命令是怎么实现的

在/Python-2.7.8/Objects/object.c中

  1. 1963 /* Implementation of dir() -- if obj is NULL, returns the names in the current
  2. 1964 (local) scope. Otherwise, performs introspection of the object: returns a
  3. 1965 sorted list of attribute names (supposedly) accessible from the object
  4. 1966 */
  5. 1967 PyObject *
  6. 1968 PyObject_Dir(PyObject *obj)
  7. 1969 {
  8. 1970 PyObject * result;
  9. 1971
  10. 1972 if (obj == NULL)
  11. 1973 /* no object -- introspect the locals */
  12. 1974 result = _dir_locals();
  13. 1975 else
  14. 1976 /* object -- introspect the object */
  15. 1977 result = _dir_object(obj);
  16. 1978
  17. 1979 assert(result == NULL || PyList_Check(result));
  18. 1980
  19. 1981 if (result != NULL && PyList_Sort(result) != 0) {
  20. 1982 /* sorting the list failed */
  21. 1983 Py_DECREF(result);
  22. 1984 result = NULL;
  23. 1985 }
  24. 1986
  25. 1987 return result;
  26. 1988 }

  

可见,与help(dir)描述的基本一致。

  1. >>> def foo(a):
  2. ... if a > x:
  3. ... return a/1024
  4. ... else:
  5. ... return a
  6. ...
  7. >>> type(foo)
  8. <type 'function'>
  9. >>> dir(foo)
  10. ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']
  11. >>> foo.__call__
  12. <method-wrapper '__call__' of function object at 0xb7420df4>
  13. >>> foo.__str__
  14. <method-wrapper '__str__' of function object at 0xb7420df4>
  15. >>> foo
  16. <function foo at 0xb7420df4>
  17. >>> foo.func_closure
  18. >>> type(foo.func_closure)
  19. <type 'NoneType'>
  20. >>> type(foo.func_code)
  21. <type 'code'>
  22. >>> foo.func_code
  23. <code object foo at 0xb7409d10, file "<stdin>", line 1>
  24. >>> dir(foo.func_code)
  25. ['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
  26. >>> foo.func_code.co_argcount
  27. 1
  28. >>> foo.func_code.co_cellvars
  29. ()
  30. >>> foo.func_code.co_code
  31. '|\x00\x00t\x00\x00k\x04\x00r\x14\x00|\x00\x00d\x01\x00\x15S|\x00\x00Sd\x00\x00S'
  32. >>> foo.func_code.co_consts
  33. (None, 1024)
  34. >>> foo.func_code.co_filename
  35. '<stdin>'
  36. >>> foo.func_code.co_firstlineno
  37. 1
  38. >>> foo.func_code.co_flags
  39. 67
  40. >>> foo.func_code.co_freevars
  41. ()
  42. >>> foo.func_code.co_lnotab
  43. '\x00\x01\x0c\x01\x08\x02'
  44. >>> foo.func_code.co_name
  45. 'foo'
  46. >>> foo.func_code.co_names
  47. ('x',)
  48. >>> foo.func_code.co_nlocals
  49. 1
  50. >>> foo.func_code.co_stacksize
  51. 2
  52. >>> foo.func_code.co_varnames
  53. ('a',)
  54. >>>

  

其中,foo.func_code.co_code打印出来的就是Python的字节码。

  1. Help on built-in function ord in module __builtin__:
  2.  
  3. ord(...)
  4. ord(c) -> integer
  5.  
  6. Return the integer ordinal of a one-character string.

  

  1. >>> [ord(i) for i in foo.func_code.co_code]
  2. [124, 0, 0, 116, 0, 0, 107, 4, 0, 114, 20, 0, 124, 0, 0, 100, 1, 0, 21, 83, 124, 0, 0, 83, 100, 0, 0, 83]

这就是那些组成python字节码的字节。解释器会循环接收各个字节,查找每个字节的指令然后执行这个指令。需要注意的是,字节码本身并不包括任何python对象,或引用任何对象。

如果你想知道python字节码的意思,可以去找到CPython解释器文件(ceval.c),然后查阅100的意思、1的意思、0的意思,等等。  

  1. >>> import dis
  2. >>> dir(dis)
  3. ['EXTENDED_ARG', 'HAVE_ARGUMENT', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_have_code', '_test', 'cmp_op', 'dis', 'disassemble', 'disassemble_string', 'disco', 'distb', 'findlabels', 'findlinestarts', 'hascompare', 'hasconst', 'hasfree', 'hasjabs', 'hasjrel', 'haslocal', 'hasname', 'opmap', 'opname', 'sys', 'types']
  4. >>> type(dis.dis)
  5. <type 'function'>
  6. >>> dir(dis.dis)
  7. ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']
  8. >>> [ord(i) for i in dis.dis.func_code.co_code]
  9. [124, 0, 0, 100, 1, 0, 107, 8, 0, 114, 23, 0, 116, 1, 0, 131, 0, 0, 1, 100, 1, 0, 83, 116, 2, 0, 124, 0, 0, 116, 3, 0, 106, 4, 0, 131, 2, 0, 114, 53, 0, 124, 0, 0, 106, 5, 0, 125, 0, 0, 110, 0, 0, 116, 6, 0, 124, 0, 0, 100, 2, 0, 131, 2, 0, 114, 80, 0, 124, 0, 0, 106, 7, 0, 125, 0, 0, 110, 0, 0, 116, 6, 0, 124, 0, 0, 100, 3, 0, 131, 2, 0, 114, 107, 0, 124, 0, 0, 106, 8, 0, 125, 0, 0, 110, 0, 0, 116, 6, 0, 124, 0, 0, 100, 4, 0, 131, 2, 0, 114, 246, 0, 124, 0, 0, 106, 9, 0, 106, 10, 0, 131, 0, 0, 125, 1, 0, 124, 1, 0, 106, 11, 0, 131, 0, 0, 1, 120, 174, 0, 124, 1, 0, 68, 93, 85, 0, 92, 2, 0, 125, 2, 0, 125, 3, 0, 116, 2, 0, 124, 3, 0, 116, 12, 0, 131, 2, 0, 114, 154, 0, 100, 5, 0, 124, 2, 0, 22, 71, 72, 121, 14, 0, 116, 13, 0, 124, 3, 0, 131, 1, 0, 1, 87, 110, 28, 0, 4, 116, 14, 0, 107, 10, 0, 114, 234, 0, 1, 125, 4, 0, 1, 100, 6, 0, 71, 124, 4, 0, 71, 72, 110, 1, 0, 88, 72, 113, 154, 0, 113, 154, 0, 87, 110, 78, 0, 116, 6, 0, 124, 0, 0, 100, 7, 0, 131, 2, 0, 114, 18, 1, 116, 15, 0, 124, 0, 0, 131, 1, 0, 1, 110, 50, 0, 116, 2, 0, 124, 0, 0, 116, 16, 0, 131, 2, 0, 114, 46, 1, 116, 17, 0, 124, 0, 0, 131, 1, 0, 1, 110, 22, 0, 116, 14, 0, 100, 8, 0, 116, 18, 0, 124, 0, 0, 131, 1, 0, 106, 19, 0, 22, 130, 2, 0, 100, 1, 0, 83]

  

  1. >>> dir(dis.dis.func_code)
  2. ['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
  3. >>> dis.dis.func_code.co_filename
  4. '/usr/lib/python2.7/dis.py'
  5. >>> dis.dis.func_code.co_consts
  6. ('Disassemble classes, methods, functions, or code.\n\n With no argument, disassemble the last traceback.\n\n ', None, 'im_func', 'func_code', '__dict__', 'Disassembly of %s:', 'Sorry:', 'co_code', "don't know how to disassemble %s objects")
  7. >>> dis.dis.func_code.co_names
  8. ('None', 'distb', 'isinstance', 'types', 'InstanceType', '__class__', 'hasattr', 'im_func', 'func_code', '__dict__', 'items', 'sort', '_have_code', 'dis', 'TypeError', 'disassemble', 'str', 'disassemble_string', 'type', '__name__')
  9. >>> dis.dis.func_code.co_varnames
  10. ('x', 'items', 'name', 'x1', 'msg')
  11. >>> dis.dis.func_code.co_stacksize
  12. 6
  13. >>> dis.dis.func_code.co_nlocals
  14. 5

  

其实dis.dis也不过就是是一连串的字节码而已,它被Python解释器执行,从而完成指定的功能。

下面我们就使用dis.dis来反汇编一下字节码

  1. >>> dis.dis(foo.func_code.co_code)
  2. 0 LOAD_FAST 0 (0)
  3. 3 LOAD_GLOBAL 0 (0)
  4. 6 COMPARE_OP 4 (>)
  5. 9 POP_JUMP_IF_FALSE 20
  6. 12 LOAD_FAST 0 (0)
  7. 15 LOAD_CONST 1 (1)
  8. 18 BINARY_DIVIDE
  9. 19 RETURN_VALUE
  10. >> 20 LOAD_FAST 0 (0)
  11. 23 RETURN_VALUE
  12. 24 LOAD_CONST 0 (0)
  13. 27 RETURN_VALUE

  

  

Python字节码与解释器学习的更多相关文章

  1. 任何Python线程执行前,必须先获得GIL锁,然后,每执行100条字节码,解释器就自动释放GIL锁,让别的线程有机会执行

    任何Python线程执行前,必须先获得GIL锁,然后,每执行100条字节码,解释器就自动释放GIL锁,让别的线程有机会执行 多线程 - 廖雪峰的官方网站 https://www.liaoxuefeng ...

  2. Python 字节码是什么

    了解 Python 字节码是什么,Python 如何使用它来执行你的代码,以及知道它是如何帮到你的. 如果你曾经编写过 Python,或者只是使用过 Python,你或许经常会看到 Python 源代 ...

  3. Python字节码介绍

    了解 Python 字节码是什么,Python 如何使用它来执行你的代码,以及知道它是如何帮到你的.如果你曾经编写过 Python,或者只是使用过 Python,你或许经常会看到 Python 源代码 ...

  4. 浮生半日:探究Python字节码

    好吧!“人生苦短,请用Python”,作为python爱好者以及安全从业者,而且最近也碰到了一些这方面的问题,懂点python字节码还是很有必要的. Python是一门解释性语言,它的具体工作流程如下 ...

  5. Python逆向(五)—— Python字节码解读

    一.前言 前些章节我们对python编译.反汇编的原理及相关模块已经做了解读.读者应该初步掌握了通过反汇编获取python程序可读字节码的能力.python逆向或者反汇编的目的就是在没有源码的基础上, ...

  6. Python 字节码bytecode

    字节码bytecode python把源码文件编译成字节码文件,存放在__pycahe子目录内,用.pyc结尾.之后如果不再修改源码文件,运行时则使用*.pyc文件编译成机器码,这样不但运行速度快,而 ...

  7. 使用uncompyle2直接反编译python字节码文件pyo/pyc

    update:在Mac OS X版的September 10, 2014版(5.0.9-1)中发现安装目录中的src.zip已更换位置至WingIDE.app/Contents/Resources/b ...

  8. python 字节码死磕

    前言:  如果你跟我一样,对python的字节码感兴趣,想了解python的代码在内存中到底是怎么去运行的,那么你可以继续往下看,如果你是python新手,我建议你移步它处,本文适合有点基础的pyth ...

  9. python字节码,java字节码,十六进制相互转换

    下面是互相转换的代码: 有想要了解更多关于python知识的请在下方评论或私信小编

随机推荐

  1. dp(最长公共上升子序列)

    This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence ...

  2. Codeforces 1105C (DP)

    题面 传送门 分析 这种计数问题,要不是纯数学推公式,要不就是dp 先处理出[l,r]中除3余0,1,2的数的个数,记为cnt0,cnt1,cnt2 设\(dp[i][j]\)表示前i个数的和除3余j ...

  3. Codeforces 1097D (DP+分解质因数)

    题目 传送门 分析 考虑\(n=p^q\)且p为质数的情况 设dp[i][j]表示经过i次变化后数为\(p^j\)的概率 则初始值dp[0][q]=1 状态转移方程为\(dp[i][j]=\sum{} ...

  4. smarty中判断数组是否为空的方法

    1,用count来取得数组的下标个数 下面例子中,如果$array为空则不输出任何数据 以下为引用的内容:{if $array|@count neq 0 }... ...{/if} 2,直接来判断 以 ...

  5. bzoj3270 博物馆(期望+高斯消元)

    Time Limit: 30 Sec  Memory Limit: 128 MB 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博物馆.这座博物馆有着特别的 ...

  6. JVM(3) 之 内存分配与回收策略

    开发十年,就只剩下这套架构体系了! >>>   之前讲过虚拟机中的堆,他是整个内存模型中占用最大的一部分,而且不是连续的.当有需要分配内存的时候,一般有两个方法分配,指针碰撞和空闲列 ...

  7. BUUCTF--xor

    测试文件:https://buuoj.cn/files/caa0fdad8f67a3115e11dc722bb9bba7/7ea34089-68ff-4bb7-8e96-92094285dfe9.zi ...

  8. shell函数与位置参数举例

  9. Android_Refrogit与RxJava结合使用(转)

    Refrogit与RxJava结合的使用    达到了非常简单就可以完成请求网络 一:1.0示例: 1.导入依赖 compile 'io.reactivex:rxjava:1.3.4'compile ...

  10. OpenStack虚拟机网络问题

    当发现你的OpenStack虚拟机网络有问题,不妨先试一下这16个步骤   1. Security Group全部打开,这是最基本的,但是很多人容易忘记 其实遇到过无数这种场景了,Debug了半天网络 ...