Development

Learning Python

I was asked today “How do I learn python?” (I’m not making this up, that is a direct quote lifted right out of the chat log!)

Of course my first response was “start at python.org” (as it would be.) That is all well and good, but I started thinking about what specific things helped me? So, here are some specifics that might work well for you if, like me, you learn about half and half from reading (theory) and doing (practice.)

The first step, of course, is to download Python. You don’t need a fancy IDE to develop in Python, although if you have one you are comfortable with and use all the time, chances are that it has a Python plugin. (I know Eclipse does, and I believe NetBeans does, and jEdit has a Python client plugin that lets you run Python code right in the editor.) If you don’t want to muck about with an IDE, though, Python comes with it’s own lightweight editor, IDLE. Open it up, play around a bit.

Ok, so you’re looking at IDLE thinking “well, there isn’t much here is there?” You’re right – time for step two. Head over to the beginner’s guide and go for it! There are tutorials aimed at people who are new to Python and to programming in general, and people who are new to Python but not to programming. There is even a list of Python courses you can buy, and a fairly large list of introductory Python books for those who learn best that way. There isn’t much I can say that isn’t there already. I kind of wish that I had started there myself. When I started playing with Python I skipped over this and went straight for the documentation and googling for specific answers, as I was trying to build a script that I needed at the time to parse 1 -2 GB log files. Java was too much tool for the job, I didn’t have access to a beefy enough Linux box to do it in Bash and PHP was doing nothing but running out of memory. It made for a bit of a rough entry into Python, but I kind of like that sort of challenge.

Which brings us to step three – build something. No, not a “Hello World” app, but something useful, in the immediate sense. Something that will make you smile, or make your life simpler, or even something that will allow you to tick off an item on your to-do list.

So what (besides the end of my rambling in parenthetical asides) are you waiting for?

2 comments Learning Python

Was there a particular reason you decided to start learning python?

Well, the primary reason was that it was something I had been meaning to do “when I got around to it.” When I ran into a problem where the tools I had at my disposal were not up to the task (including having built the same parser in Java where it ran against a 1.2 GB file for about half an hour and then died, and PHP where it ran against the same file for about 10 minutes before dying) I figured it was as good a time as any to add a new tool to my belt.

BTW, the Python parser I wrote not only worked well, but chewed through all the log files I had in batch in under 10 minutes. My first reaction was that it had either died or didn’t parse them correctly and I deleted all the output files to start over. I ran it again, under 10 minutes again, and none of the error messages I added at all the possible failure points showed up. I looked over the output files and was absolutely floored. I have been hooked ever since.

Comments are closed.