[Ilugc] Fwd: [Chennaipy] September meet minutes

  • From: tshrinivasan@xxxxxxxxx (Shrinivasan T)
  • Date: Mon, 30 Sep 2013 14:35:01 +0530

---------- Forwarded message ----------
From: Abhishek <bigbeliever@xxxxxxxxx>
Date: Mon, Sep 30, 2013 at 11:51 AM
Subject: [Chennaipy] September meet minutes
To: chennaipy at python.org


# September meet minutes

The September meetup for Chennai.py was held at Zilogic Systems office
at 3-5pm on Sat 28 Sep2013.
Nearly 20 people attended it. The meet started with Vijay giving an
introduction on the Python language before going into his talk on
ByteCode Hacking. It included a comparison of Python with C, with
reference to Python's dynamic type system. The examples of signed and
unsigned integers and buffer sizes in C were used for comparison.

## Bytecode hacking by Vijay Kumar

The talk started off with an example implementation of a new
programming language. There were two approaches to writing the code,
first was string based and the second byte-code based. [I don't have
the examples here, please add]. The first was more human readable
while the second was faster. Python langauge does both - programs are
written as human readable strings, and they are converted to a byte
code on first execution. All subsequent executions use the byte code
only (saved as a .pyc file) to avoid the parsing overhead. This also
happens on the Python prompt.

After this there were details on how the Python interpreter reads
objects from the heap, updates them and then stores them back. This
process of object manipulations happens using the byte-code
instructions. The code objects are also stored in the heap only. The
interpreter uses a stack machine while operating on these objects. The
objects are stored by reference and not by value. There was some more
discussion on what stack and register machines were. The JVM also uses
a stack machine, while examples of register machine were Android, Lua
and the Dalvik VM (for performance reasons I think).

Next there was a demonstration on how the bytecode looks and works for
a sample method -

def hello():
 print "Hello world"

There's a handy '__code__' property on the method object ('hello'
here) which gives the code object. The code object contains a lot of
meta-data about the piece of code. It contains the bytecode as the
'co_code' property. So the following gets the byte code -

hello.__code__.co_code

That would show the bytecode as a hex text, and to see it in more
readable form, we can use the 'disassemble' method from 'dis' library.

    dis.disassemble(hello.__code__)
  0 LOAD_CONST               1 ('Hello World')
  3 PRINT_ITEM
  4 PRINT_NEWLINE
  5 LOAD_CONST               0 (None)
  8 RETURN_VALUE

Here he explained how the each part of the byte-code is working. After
this there was another example using a 'sum_ab', and then another one
for a loop. (More details in the ipynb document:
https://github.com/bravegnu/python-byte-code). The loop example
demonstrated how the byte-code performs the jump operation using the
JUMP_ABSOLUTE and POP_JUMP_IF_FALSE byte-code instructions. The talk
ended at an interesting implementation of 'goto' (which doesn't exist
in Python) using byte-code manipulations. This would be covered at a
talk in the next meetup.

In between there was also a discussion on why to learn bytecode
manipulation, on which the speaker mentioned that it was not necessary
and one can be a good Python programmer without knowing it, but it is
good fun and helps us understand how the language works internally. He
also mentioned the activestate recipes site where many such
interesting code snippets can be found. (which I think is this:
http://code.activestate.com/recipes/langs/python)


## Python environment setup by Prasanna Venkatesh

This started with Venkatesh talking about Pep008 and Autopep8, which
are tools for helping encorce styling on Python programs. There is a
standard style guide maintained by the Python community (I forgot the
name of the guide) which details on how Python code should look. It
describes things like the spaces between operands, number of
spaces/tabs for indentation etc. The pep008 command tells us where all
the guidelines are violalted in our code, and autopep corrects them.
There was a philisophical discussion about why one should follow such
a style guide and not have one's own style. On which the speaker
mentioned it is better to follow standard styles if the code has to be
open sourced.

Then he proceeded to talk about pip. Pip is the installer tool for
Python libraries. Most Python libraries are published at python.org,
and pip fetches and installs them to our computer. It is a replacement
for 'easy_install' which was used earlier for the job. pip comes with
a few subcommands like 'pip install', 'pip search', 'pip uninstall'
and 'pip freeze'. pip freeze is notable here, as it can be used to
freeze the versions of libraries used for a project and write them to
a 'requirement.txt' file. When needed, all the mentioned libraries and
versions on the file can be installed accurately using -

pip install -r requirements.txt

After this the topic covered was 'vitualenv'. The purpose of
virtualenv is to isolate the python enviroment at the project level,
such that multiple projects on a computer can have a separate python
version and separate set of libraries that don't interfere with each
other. virtualenv creates the environments on separate directories
that can get scattered all over, so there's a 'virtualenvwrapper' that
keeps it cleaner. [Please help me expand this part as I didn't take
down the examples.]

There was also a discussion on whether pip will overwrite an existing
library if a new version has come, and the conlusion was that its
better to specify the version number in pip when such a scenario is
likely. There was also a discussion on the comparison between the
python byte-code and JVM byte-code. Here the main difference stated
was that Python byte-code is 'closer' to the code, and Java's
byte-code is 'closer' to the machine. And Python's byte-code is
dependent on the Python version too.

That's all. Please add/correct if I missed something here.
Thanks,
Abhishek














_______________________________________________
Chennaipy mailing list
Chennaipy at python.org
https://mail.python.org/mailman/listinfo/chennaipy



-- 
Regards,
T.Shrinivasan


My Life with GNU/Linux : http://goinggnu.wordpress.com
Free E-Magazine on Free Open Source Software in Tamil : http://kaniyam.com

Get CollabNet Subversion Edge :     http://www.collab.net/svnedge

Other related posts:

  • » [Ilugc] Fwd: [Chennaipy] September meet minutes - Shrinivasan T