My First Python Experience

Album Cover: In Rainbows

"Words are a sawed-off shotgun."
Radiohead / Jigsaw Falling Into Place

Posted on May 01, 2009 7:34 PM in Programming
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

Despite stumbling into Python territory in the past, I wrote my very first Python script today. Rather than opting for Hello World (does anyone actually write these?), I dove in head first and created a script that parsed an Excel file (.xls), using the Python package xlrd, and used cell contents from the file to output an XML file.

Despite not having a single source of documentation, it only took me a few hours to get a working script put together. Dive Into Python is great if you want a good introduction to the language, but when it comes to practical things like if statements, for loops and efficiently concatenating and formatting strings, I found I had more luck with the good ol' Google command line (e.g. "for loops python").

A few things I learned the hard way (i.e. I tried to do them using habits from other languages and they just didn't work) were that there is no pre- or post-increment support in Python and that functions have to be declared in Python before they are used. That latter realization is hard to come by. I couldn't find a single page covering functions in Python that spelled this out clearly. That combined with the "NameError" you get when you don't follow this rule is unintuitive enough to make this issue a lot harder on newbies like myself than it should be. However, once you grasp the fact that functions are treated like variables in Python, it all starts to make sense.

One thing I've heard over and over in regard to Python is the fact that it is so strict about indentation. But seriously, once you start writing a Python script, it's second nature. If you're any good with other scripting languages, you've probably been doing this already anyway.

Overall, I was impressed by the language. It didn't feel like the same learning curve of Perl, most likely because of the lack of all the $, $@ and $_ types of "features." Parts of Python seem like they were changed just to be different (e.g. the aforementioned incrementing issue and the use of None instead of null) and without any real rhyme or reason, but I'm still just a newbie so maybe those types of things will become clearer to me once I've had more experience with the language.

The important takeaway is that I do intend to get more experience with the language. Even as a total newbie, I was able to generate a semi-complex script in a few hours. The script is readable, fairly compact, and just works. That's what you want from any scripting language in your tool belt. I'll likely be posting more thoughts on Python here in the future as my experience with the language broadens.


Ian Clifton on May 02, 2009 at 11:39 PM:

Don't let it suck you in!

Actually, I think Python can be great for little scripts (convert X data into Y data), and the bit I've played around with pygames has been fun too. There are some quirks to get used to (such as "None" as you mentioned or the lack of a case statement), but most aren't major problems in the majority of cases. The indentation issue isn't ever a problem if you work solo or with small groups unless you try to copy and paste or otherwise mix code from outside sources. The one interesting thing with that, though, is the fundamental difference in the importance of whitespace in Python vs. HTML. That leads to a lot of different possibilities in MVC web frameworks.


gqxrikqg on May 15, 2017 at 5:22 AM:

Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.


Email Address:



Check this box if you hate spam.