<div dir="ltr"><div># October meet-up minutes</div><div><br></div><div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">The October meetup for Chennai.py was held at Zilogic Systems at 3-5pm on Sat 26 Oct2013. Nearly 20 people attended it. There was one talk this time - concluding edition of Python Bytecode Hacking by Vijay Kumar. </div>
</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">## Bytecode hacking by Vijay Kumar<br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<br></div><div>The speaker started with a brief introduction to Python for the new members, and then proceeded to give a recap of the first part of his talk. He had given the first part of the talk at the previous meet-up in September.</div>
<div><br></div><div>The first part had details of the Python bytecode, some basics of Python interpreter operation and related tools and libraries. In this part, the agenda was to implement 'goto' functionality as an example application of bytecode manipulation. Goto is not present in the language by default, and the idea was to modify bytecode at necessary points to get the jump-effect of goto. The code example used was -</div>
<div><br></div><div><div>      def test_goto(n):</div><div>          s = 0</div><div>          label .myLoop        #  NOP here</div><div>          if n <= 0:</div><div>              return s</div><div>          s += n</div>
<div>          n -= 1</div><div>          goto .myLoop        # JUMP_ABSOLUTE to label. myLoop line</div></div><div><br></div><div>By default the test_goto function would fail on <i>label</i>, but by replacing its bytecode with NOP and JUMP_ABSOLUTE instructions function can be made to work.</div>
<div><br></div><div>There were separate methods (<span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;white-space:pre">nop_labels, </span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;white-space:pre">inject_jump)</span> used for doing this on the generated bytecode. The new bytecode was used to construct an entirely new code object, which is used to construct a new function. The new function is then added as a decorator on the existing <i>test_goto</i> function. The entire code can be found in the previously shared ipynb[1]. Vijay, please also add code samples to the talk-repo[2] if possible.</div>
<div><br></div><div>In between, there was a discussion on immutables on Python. Strings are immutable, and so are tuples. This advantage of this is improved efficiency. The speaker described a few ways of modifying a string, and one member (Aswin) mentioned that there was a library that allowed the creation of mutable strings. Aswin, please share the a link to the library here.</div>
<div><br></div><div>There was also a discussion on Pymite [3] which is a very lightweight (~32/64kb) python bytecode interpreter that can be used in things like embedded systems. And then about another project called Pyside [4], which has Qt bindings for Python and can be used for desktop applications. The other alternatives mentioned were: Wx [5], Gtk [6], Tk [7]. All of them work cross platform, but get native look and feel to varying degrees.</div>
<div><br></div><div>Please add/correct anything I missed here.<br></div><div>Regards,</div><div>Abhishek</div><div><br></div><div>---- </div><div><br></div><div>[1]: <a href="http://nbviewer.ipython.org/urls/raw.github.com/bravegnu/python-byte-code/master/Python%2520Byte%2520Code%2520Hacking.ipynb">http://nbviewer.ipython.org/urls/raw.github.com/bravegnu/python-byte-code/master/Python%2520Byte%2520Code%2520Hacking.ipynb</a><br>
</div><div>[2]: <a href="https://github.com/bravegnu/python-byte-code">https://github.com/bravegnu/python-byte-code</a></div><div>[3]: <a href="https://wiki.python.org/moin/PyMite">https://wiki.python.org/moin/PyMite</a></div>
<div>[4]: <a href="http://qt-project.org/wiki/PySide">http://qt-project.org/wiki/PySide</a></div><div>[5]: <a href="http://www.wxpython.org/">http://www.wxpython.org/</a></div><div>[6]: <a href="http://www.pygtk.org/">http://www.pygtk.org/</a></div>
<div>[7]: <a href="https://wiki.python.org/moin/TkInter">https://wiki.python.org/moin/TkInter</a></div></div>