thoughts = rand()

Wednesday, February 6, 2008

Python aha moment #1 - cruising through a text file

I am planning to write a series of blogs documenting all my "aha" moments with Python. The "aha" moments are those times at which I come across some piece of Python code and murmur to myself - "Python seems to be really cool!"

So here is my first aha moment - cruising through a text file:

for line in file("C:\\Windows\\System32\\drivers\\etc\\hosts"):
     print line

The above lines of Python code will:

a) open the 'hosts' file
b) print every line of that file to the console, and
c) close the file after all the lines are read.

This is a really productive way of parsing text files!

Friday, January 25, 2008

Good programming practices

Sometime back in life - precisely 2003, I came across a nice article in the web describing a gross list of good programming practices. I read it, found it amusing, took a print out of it, filed it and just forgotten about it.

I was cleaning up my room after a very very long time and got noticed of that old print out that I took in 2003. Now, after 5 years with the eyes of experience I looked at it again. To my astonishment I found that the list is indeed a really really good list of programming practices. After fair amount of Googling, located the original version of it!