1 Broken Scooter, 4 Iron Cots, 1 Used Ford, 3 Cats, and 1 Small Room

Yet another Self-Important Blog.

Rohit Singh
Email Me

Use as directed or at your own risk.

These are a few of my favourite links.

Commenting and Trackback by HaloScan.com


Sat, 29 Apr 2006

I Love Python

It's the best scripting language I've played with. I can think about the code in English and, very often, the Python version isn't that different. This makes coding in it that much faster than anything else.

For example, during writing some code I realized I was getting protein IDs with their version numbers, e.g. NP_10023.1, while I just wanted to get the IDs. These are the kind of minor roadblocks that you always have when dealing with bioinformatics databases. Now, here the version number is preceded by a dot, ".". So, in English, the logic goes like this: "if the word has a '.' in it, then find the position of '.' in the string and take the part before the position". Here's the Python code:

if '.' in word:
   word = word[ : word.index('.')]

That's it. Now, the point is not to show that this really short example couldn't be done in some other language in an equally short way, if not shorter. The point is: what I think is essentially what I have to write. I don't need to remember what the language's equivalent of strchr() would be. The most obvious thing ('.' in word) works. That makes coding much more natural.

[/rants-and-raves] | | | permalink