inpycon09 the success story

When the first discussions happened, everybody doubted it might become just another conference discussion that will never happen. It has taken the support and sheer determination of quite a number of people to make it happen. We just wanted to try it once, to at least see how the Python community responds to such initiatives and it has ended up being more than encouraging to make this a yearly event. This is the simple story of inpycon09.

When I landed at the IISc campus on a not so chilly morning, the posters were up and I could find a few people waiting here and there in the corridors. When I entered nothing was up yet, other than a few volunteers running around putting posters and direction notices. Slowly people started turning up and I could see more known faces. By 9 AM, there were enough crowd to start the registration counter and soon a long queue got formed.

The conference kit consisted of a notepad, ID tag, a pen and a pycon tee. It was a simple white tee, with a caption in the back. Unfortunately we ended up having a spello in it, which indeed made the tee more special ;-) Halls were fast filling up and when Prabhu Ramachandran was delivering the keynote the benches got filled and people started filling up the foot steps as well. It was a very interesting talk, encouraging everyone to go and give a shot with Python. He had also included his associations with ILUGC and how it helped him. He advised people to become a part of an active LUG. His talk was mostly around SciPy and Mayavi.

As the keynote ended, talks in other two halls started, kicking the normal proceedings of the first day of inpycon. Every hall was running full house and we would’ve had around 300 people attending the conference, especially a big bunch of students of REC, Chennai. Kenneth and Noufal took the Introduction to Python talk, leaving me for the second day. There was actually a balance of talks, not just focusing on web development. And the lunch was really good.

A lot of #linux-india guys had turned up and it was surprising to meet them before the normal foss.in season. The first day ended up quite satisfactorily and gave us hopes for the second day to run smoothly. Though we did not have a huge crowd on the second day, and it being only a half day of scheduled talks, it too went calmly. I took the beginners’ introduction to Python, following by Kenneth taking some advanced topics. There was a white sheet posted with post-it notes to be used to express the feedbacks from delegates and we ended up getting some quite interesting, even contradicting opinions posted about the conference. We welcome the criticisms as it helps us to know our holes and stop it from appearing next time.

On the whole, the beta release of inpycon was a satisfying success, leaving my weekend to have not been wasted and giving us the encouragement to come back better next year, may be in Chennai ;-)

PyCon in India

PyCon is the annual conglomerate of Python community at various places around the globe. It is an occasion which brings together the developers, users and business community around Python, serving as a platform to interact and share each others’ views and experiences.

There was always an idea to have once such conference in India, but the need for it has become stronger of late in the BangPypers mailing list that has given to numerous threads of discussions going on in the mailing list. Also a formal proposal is getting drafted as well as open discussions happening in the wiki were people can pen down their opinions and ideas.

The month of September has been proposed for the tentative time for PyCon India to happen, but it is still under discussion. The few hot topics among the on-going discussions are whether to have tee-shirts available or should we have more useful stuffs like Python cheat-sheet given as a part of delegate kit. Also, what’s the level and mode the conference should take up being the first such event in India is also a point to decide upon.

Baiju also raised the idea of inviting Guido to open up the conference, as they would be having an opportunity to meet him during the PyCon in Chicago to happen soon.

Another point to remember is that PSF doesn’t want numerous PUGs in the country to have their own PyCons, which means all PUGs within India should put their heads together and organize a PyCon in the country together. This means we can have the PyCon each year at a new location, and the decision can be made during the current year’s PyCon about the next year’s venue. As the initial discussion has started in BangPypers, the beginning will most probably happen in Bangalore.

I know only three active PUGs in India, the BangPypers, the ChennaiPy and MumPy (which is pretty infant comparing the other two). If you know of any more PUGs, please enlighten me up so I can keep them on the loop as well.

Please feel free to add your thoughts in the wiki. We will soon select an organizing committee, and despite it we will need lots of volunteers and lots of sponsors. If you are in a company using Python and would like to participate and/or sponsor in this wonderful event, then please join the BangPypers mailing list or poke us in #bangpypers in irc.freenode.net. We will soon try to have a dedicated mailing list running up for all discussion relating to the PyCon.

If you have any more points to add to this post, please drop a comment to this post and I will consider adding  it :) Let’s all make the PyCon happen in India. Python, FTW!! :)

(Python) PyProgram #8 – Cycling Alphabets

Kushal came down with a simple looking problem with constraints that might make solving it a bit not-a-needle-into-the-banana. As usual, me and Jacob sat down trying to solve it. Rather try finding various ways of solving it. The problem is, given one character within the range a-z or A-Z (not as a list, but from string.letters) we have to find the next character in the alphabetical order. When ‘z’ or ‘Z’ is encountered, the next alphabet returned should be ‘a’ or ‘A’ respectively. The constraint is that if or while conditions and for loops should not be used. And more importantly, the main solution should be of a single line. Though Kushal had a more mathematical solution, this is what me and Jacob managed to cook up as a more logical solution (note the ‘and’ and ‘or’ ;) ),

import string

def thenext(theletter):
    return ((string.letters.find(theletter)+1) %26) and (string.letters[string.letters.find(theletter)\
+1]) or (string.letters[string.letters.find(theletter)-25])

print "for 'a' i get: "+thenext('a')
print "for 'g' i get: "+thenext('g')
print "for 'z' i get: "+thenext('z')
print "for 'A' i get: "+thenext('A')
print "for 'H' i get: "+thenext('H')
print "for 'Z' i get: "+thenext('Z')

The solution looks like..

for 'a' i get: b
for 'g' i get: h
for 'z' i get: a
for 'A' i get: B
for 'H' i get: I
for 'Z' i get: A

Its hard to get one

When we were attending foss.in, we got a good news from our higher ranks at the place where we work (we = jace, kushal, me) that we can go forward and recruit some more programmers. We are also in need of a Release Manager (hopefully we are soon getting some one for this) and a Sys Admin exclusively for our team (we have one, but he is heavily loaded from all corners).

As we are basically a Python shop and work extensively on FOSS, we need some one with an exposure to both of them. It would be great if we get one with experience in Zope/Plone, but our minimal requirement is “should be able to work with python from day 0″.  We are still hunting for a Python Programmer, whom we need as soon as possible. We aren’t finding one easily, rather am getting invites from other Python shops to join them :P

If you are a programmer, who knows Python, have some exposure with Web Development, and looking for an interesting and challenging job in a nerdy environment surrounded by well known faces from the Indian FOSS community, then please poke (PM) us (jace, kushal and teKnofreak). We are always available at #linux-india @ irc.freenode.net, else leave us a memo :)

(Python) PyProgram #7 – Time Object Diffs

I had two time objects and needed to find the difference of time between them. Upon Googling, querying in #python and checking the documentation, found that there is not built-in function available for this. Though there were some cookbook recipes, I wanted to write my own solution to find the difference between two datetime.time objects. Though datetime.timedelta was for time difference requirements it only has a days, seconds and microseconds property while I need hour, minute and seconds. Thus, I wrote my timediff method which accepts two time objects btime and stime where btime is a bigger time than stime (b for big and s for small ;) ), and it returns a datetime.time object for the difference time. (Why I need to have time objects? I use storm ORM ;) )

def timediff(btime, stime):

    """Difference between two datetime.time objects

    Accepts two datetime.time objects where btime > stime

    Returns a datetime.time object of the difference in time of

    the two datetime objects.

    """

    btdelta = timedelta(hours=btime.hour, minutes=btime.minute, seconds=btime.second)

    stdelta = timedelta(hours=stime.hour, minutes=stime.minute, seconds=stime.second)

    tdiff = btdelta - stdelta

    tdiffsec = tdiff.seconds

    if tdiffsec < 60 and tdiffsec > 0:

        return time(0, 0, int(tdiffsec))

    elif tdiffsec < 3600 and tdiffsec > 0:

        tdiffsplit = str(tdiffsec/60.0).split('.')

        tdiffmin = int(tdiffsplit[0])

        tdiffsec = float("0."+tdiffsplit[1])*60

        return time(0, int(tdiffmin), int(tdiffsec))

    elif tdiffsec > 0:

        tdiffhourmin = str(tdiffsec/3600.0).split('.')

        tdiffhour = int(tdiffhourmin[0])

        tdiffminsec = str(float("0."+tdiffhourmin[1])*60).split('.')

        tdiffmin = int(tdiffminsec[0])

        tdiffsec = float("0."+tdiffminsec[1])*60

        return time(tdiffhour, tdiffmin, int(tdiffsec))

    else:

        return time(0, 0, 0)

looking for an editor that works

Been using emacs for long, though occasionally used vi as well while left alone in the terminal. Then learnt the `emacs -nw` trick for terminal emacs, created an alias (`e`) and kept moving. But sometimes I felt the need of a better editor when things did not work the way I wanted it to. Though emacs can be customized as much a Hardy Davidson can be, but not for a lazy ass like me.

Was working with webpy since morning and I had been struggling at one point since 4 p.m. It had been a single statement of using the insert function which had been messing in a mysterious manner. After trying, trying and still trying, I found out it had something to do with how it is in the file. It’s just my conclusion, but am afraid its the real reason too. Then I tried gvim, enabled syntax highlighting but it still doesn’t auto indent which I very much need while writing Python code. Thus started wondering if there is any other near to ideal editor in this world. The mac comes with one, which I have seen jace working with. But I neither have a mac book nor have it on Ubuntu.

The search for a better editor that works for me continues….

(Python) PyProgram #6 – Finding weeks of a month

My colleague had a problem, he needed to separate the dates in a month according to weeks. That is, given a month, he has to find the dates in 1st week, dates in 2nd week and so on. This is need to query and collect a weeks data for a given month. He was trying to write his own solution which we Python guys around thought was a bit non-straight forward. My other colleague Jacob sat and wrote a small Py script to order the dates per week of a given month,

from datetime import datetime, timedelta

current_date = datetime.now() year, month = current_date.timetuple()[:2]

first_day_of_month = datetime(year, month, 1)

if month == 12:

    first_day_of_next_month = datetime(year+1, 1, 1)

else:

    first_day_of_next_month = datetime(year, month+1, 1)

#Subtracting 1 day

last_day_of_month = first_day_of_next_month - timedelta(1)

#First and Last days of the month

print first_day_of_month, last_day_of_month

#Computing start and end week days

first_week_day = first_day_of_month.weekday()+1

date_range = [0]*first_week_day + range(first_day_of_month.day,

last_day_of_month.day+1)

month = []

while date_range:

    if len(date_range) >= 7:

        week = date_range[:7]

        date_range = date_range[7:]

    else:

        week = date_range

        date_range = None

     month.append(week)

for week in month:

    print week

for week in month:

    start_week, end_week = min(week), max(week)

    if start_week==0:

        start_week = 1

    print start_week, end_week

Python BoF at foss.in

I was enquiring Baiju about the Python Collective at the Bar Camp Bangalore 5, which is scheduled for this weekend, as I hadn’t seen any discussion about it in the BangPypers list. This is when Baiju asked me about having a BoF during foss.in, which I readily seconded and as per his advice, start the discussion in BangPypers list for the same. And thats why this post comes out.

We plan to have a “Python BoF” during foss.in 2007, organized by BangPypers (the Bangalore Python User Group). The discussions will happen in the BangPypers Mailing List to decide the day and time, after which I will update the tentative date and time here, as well announce it in both BangPypers and foss.in mailing lists. Hope to see a lot of Pythonians at the BoF and interesting discussions happen :)

(Python) ipython

When I was just peeping into the discussions at #python, I saw a few talking about ipython. On first look, I thought it to be Iron Python stuff but was wrong. It is an (another?) enhanced Python Shell or what we otherwise call as Interactive Python Mode. The good thing with these stuffs is you can just download and try them, not much a paining process to get them working. Hence I went for it.

Features

  • Dynamic Object Introspection : We can access docstrings, function definition prototypes, source codes of modules, source files and a lot more dynamically.

For example, after importing `os` module, typing os.path?? or os.path? gives complete source code and description of the os module respectively. Similarly `%pdoc object`gives us the object’s doctstring information.

  • Local namespace completion with TAB press.
  • Numbered input/output prompts.

In [1]: print "Hello World!"
Hello World!

In [2]: (1+2)*3
Out[2]: 9

  • User-extensible`magic` commands (type %magic for information).
  • System shell access with ! prefix.

!ls will issue the `ls` command in the system shell and print its output.

  • File system navigation with %cd command.
  • Verbose and colored exception traceback.
  • Auto-parenthesis.

>>> callable_ob arg1, arg2, arg3
and the input will be translated to this:
--> callable_ob(arg1, arg2, arg3)

  • Auto-quoting.

>>> ,my_function a b c # becomes my_function("a","b","c")
>>> ;my_function a b c # becomes my_function("a b c")

  • Embeddable within other python code/modules.

Installation

I always prefer the `svn checkout` way of getting the source code. We can get to know more about ipython at its home site. We can also get pythonreadline from the same site, which helps us to have features like color, tab, completion, etc. (I read somewhere that it is not needed for ipython as it implicitly has pyreadline). The following are the steps to install ipython from the svn repos as a local copy,

  1. We can get the source code by doing an svn checkout,
  2. svn co http://ipython.scipy.org/svn/ipython/ipython/trunk ipython

  3. We need to get into the checked out source directory and run the following command
  4. python setup.py install

  5. The –home option can be used to specify a directory to install the ipython, else it will install in the default python directories.
  6. python setup.py install --home /home/myuser/python/ipython

  7. If we are using –home option, then we need to add the following line into our.bashrc. Else we need to export the PYTHONPATH variable every time adding the path of our ipython/lib/python installation to it.
  8. export PYTHONPATH=/home/myuser/python/ipython/lib/python

  9. We can run ipython by executing ipython/bin/ipython from the shell (or create a link pointing to this file).

The complete documentation can be obtained as pdf as well as viewed as HTML.

(Python) Function calls for beginners

A function `call` is a callable object with a series of arguments which can be empty.

syntax : primary(arg_list['',''])
arg_list ::= positional_args [, keyword_ags][, *expression][, ** expression] |
keyword_args[, *expression][, ** expression] |
*expression [, **expression] |
** expression

positional_args ::= expression (, expression*)
keywords_args ::= keyword_item (, keyword_item*)
keyword_item ::= identifier = expression

`primary` is the callable object (function name, built-in callable method objs, class objs, methods of class instances and callable class instances)

How arguments are processed ?

1. a list of unfilled slots for formal parameters is created
2. N positional_args are placed in first N slots
3. keyword_args are placed in corrsponding slot using identifier

TypeError if a slot is already filled

4. Unfilled slots are filled with corresponding default values

TypeError if slots exist with no default values
TypeError if positional_args > formal param slots
TypeError if ketyword_args doesn’t match with formal param name unless **identifier is present

5. *expression evaluates to sequence like y1…yM and are placed as additional positional_args after x1…xN such that the call is made with x1….xN,y1..yM positional arguments
6. **expression is a dictionary contained excess keyword arguments

TypeError if **expression doesn’t evaluate to dictionary

7. *expression is processed before keyword arguments, hence unusual to use both keyword_args and *expression

A call return can be,

  • as per the return statement for a user-defined func
  • up to the interpreter for a build-in func or method
  • a new class instance for a class object
  • the user-defined function for a class instance method with the instance as the first argument
  • as per __call__() method for a class instance

Examples:

# define a function with two params, printing them as result
>>> def f(a,b): print a, b
...

# both are keyword_args
>>> f(a=1,b=2)
1 2

# both are positional_args
>>> f(1,2)
1 2

# a is keyword and b is considered positional. ERROR!
>>> f(a=1,2)
File "<stdin>", line 1
SyntaxError: non-keyword arg after keyword arg

# a is positional and b is keyword_arg
>>> f(1,b=2)
1 2

# 1 is positional while 2 is *expr and takes as additional positional_arg for b
>>> f(1,*(2,))
1 2

# 1 is keyword for a, but 2 is also positional_arg for a. ERROR!
>>> f(a=1,*(2,))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for keyword argument 'a'

# 1 is a keyword_arg for b, while 2 is positional_arg for a
>>> f(b=1,*(2,))
2 1

# 1 is keyword_arg for a, while 2 is specified thru **expr for b
>>> f(a=1,**{'b':2,})
1 2

# 1 is positional_arg using *expr for a, b is keyword_arg thru **expr for b
>>> f(*(1,),**{'b':2,})
1 2

# both a and b are specified as keyword_args thru **expression
>>> f(**{'a':1,'b':2,})
1 2

Original Reference (Python Reference Documentation)