[Chennaipy] October meetup minutes

Abhishek bigbeliever at gmail.com
Sun Oct 27 15:17:54 CET 2013


# October meet-up minutes

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.

## Bytecode hacking by Vijay Kumar

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.

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 -

      def test_goto(n):
          s = 0
          label .myLoop        #  NOP here
          if n <= 0:
              return s
          s += n
          n -= 1
          goto .myLoop        # JUMP_ABSOLUTE to label. myLoop line

By default the test_goto function would fail on *label*, but by replacing
its bytecode with NOP and JUMP_ABSOLUTE instructions function can be made
to work.

There were separate methods (nop_labels, inject_jump) 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
*test_goto*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.

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.

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.

Please add/correct anything I missed here.
Regards,
Abhishek

----

[1]:
http://nbviewer.ipython.org/urls/raw.github.com/bravegnu/python-byte-code/master/Python%2520Byte%2520Code%2520Hacking.ipynb
[2]: https://github.com/bravegnu/python-byte-code
[3]: https://wiki.python.org/moin/PyMite
[4]: http://qt-project.org/wiki/PySide
[5]: http://www.wxpython.org/
[6]: http://www.pygtk.org/
[7]: https://wiki.python.org/moin/TkInter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chennaipy/attachments/20131027/9bcf03ea/attachment.html>


More information about the Chennaipy mailing list