Friday, October 1, 2010

Python

Yesterday I wrote my first python script:
os.system('lookAtStuff.pl')
Awesome, no? Alright, that was not really the script. I have used perl as my scripting language of choice since High School.

My current manager has been trying to convert me to python for many months. The problem has been that I only use a scripting language when I want to do something quick, and if I want to do something quick I do not want to learn a new language before it gets done. That is kind of lame excuse, but it is all I have.

There are really two powerful features in perl that keep me coming back. Yesterday, I dug around and found out how to do those features in python.

  • Regular expressions - I spent a summer writing regular expressions to tag corpora for Kurzweil Applied Intelligence (right after they were sold to Lernout & Hauspie). Since that time I have used perl's regular expressions extensively. At first glance, python's regular expressions are a bit clumsy and awkward, but at least it has them. I found the official documentation very useful. The main tricky points being the "The Backslash Plague" and using search instead of match. I think they did that just to be ornery. Python has to "compile" the regular expression before using it, but I am used to that from C++.
  • System commands - I normally use my perl scripts to glue together other programs or batch runs together. I have perl call these other programs directly, and sometimes I pipe in the output as a file. Python can do that to, but (like regular expressions) it feels a bit clumsy and awkward to me. The official documentation is useful. For my little script I used listdir and popen. I expect I will use the system command in the future.
I have so far found printing in python to be a nuisance, but I also have not had any kind of epiphany there yet either. I expect that after I use it for a while I will "see the light."

That's my $0.02, and my journey in the world of python has officially started. Know of any quality, free, online, and concise references for Python?

1 comment:

  1. I would post a comment if I had any idea what you're talking about!

    ReplyDelete