>>> class Point(object): ... pass >>> p = Point() >>> p.x = 10 >>> p.y = 20
[ Home | Feed | Twitter | Vector Art | Ascii Art | Tutorials ]
We had a great meet this time, with about 10 people participating. We started with the customary introduction to Python, since there were lot of people who had just started with Python.
We then moved on to the "Classes and Methods" talk by Rengaraj. Rengaraj demonstrated classes and objects by creating an empty class called Point, instantiating it, and then adding members to the object.
>>> class Point(object): ... pass >>> p = Point() >>> p.x = 10 >>> p.y = 20
He then showed how to create a initialized object by defining the __init__() method. He also explained the mandatory first argument, which is used to pass the object itself. He then added another helper method to calculate the distance of the point from the origin. One question worth mentioning was raised by Gurpreet. He was surprised that attributes get created by just assigning to them. He wanted to know if this is good or bad? Vijay explained that the Python, unlike languages like Java, doesn’t constrain the developer too much. It gives freedom to the developer, and the developer is supposed to use freedom with responsibility.
We then moved on to the "Idioms and Anti-Idioms" talk by Vijay. Vijay first explained an anti-idiom with module import. He explained why from module import * is bad. He showed how that can overshadow built-ins, local definitions and definitions from other modules. He said the better way to do this is to explicitly specify the definitions required from the module, as in from module import x, y, z
He then moved on to another anti-idiom with exceptions. He explained why a blanket try ... except block, as shown below is bad.
try: fp = open(filename) except: print "error opening file"
He showed what happened when the open function was misspelt, and how it mattered more in Python, than in other languages like Java. He then explained the right way to do it, is to explicitly specify the exception to catch.
After the talks, Vijay wanted know anybody was interested in giving a talk next meet. Arunram, Rengaraj and Gurpreet offered to talk in the next meet. He also asked for suggestions, for Chennaipy, and the following topics were suggested for the upcoming meets.
GUI toolkits
Socket programming
Algorithm implementation
Vijay also suggested that we take up a small program, implement it and then review the implementation during the next meet. He also suggested that we could iterate this by adding more features. He said he will be sending out a mail asking for suggestions on the program to implement.
Gurpreet, raised a question about doctest. He wanted to know if that was good way of unit testing code. Vijay, put the audience to perspective by telling them what docstrings are and what doctests are. He then explained that doctests were used to ensure that the documentation is in sync with the code, and not the other way around. And that, it is not the best way to do unit testing.
With this, we came to the end of another wonderful Python meet.
Permalink | Add Comment | Share: Twitter, Facebook, Buzz, ... | Tags: chennaipy, python