Skip to main content

Taking the Python Plunge


I'm finally doing it. I'm learning Python through Codecademy's online tutorials.

So far, I really like Python. Everything is natively object oriented, so every variable is born as an object. Working within the paradigm has already shown me how much time I spend wrestling with IDL to make it work more like an object-oriented programming language, when it simply isn't. I've been known to call my style within IDL as Pseudo Object Oriented Programming, or POOP. It's often just as ugly as it sounds. So, philosophically, I'm finding that Python is well aligned with my programming style and needs.

Big ups to my student, Tim, for helping me with some of the nuances of Python arrays and syntax. He also pointed me to the Enthought Canopy programming environment, which is a great way to write code. Think of it as IDL's Development Environment, but less clunky.

I'm planning to start a new research project built solely on Python. It's a bit daunting, but I figure the only way to learn is to dive right on in. If you have any encouragement to lend, I could use it!

BTW, the Codecademy tutorials are a lot of fun, too. Here's a little easter egg that one of their "PSAs" alerted me to:


In [1]: import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Comments

Comrade said…
Great to hear you're moving to Python! Some resources I really like:
Python 4 Astronomers: http://python4astronomers.github.io/

Astropython blog:
http://www.astropython.org/

Astropy project: http://www.astropy.org/

Astropy user mailing list: http://mail.scipy.org/mailman/listinfo/astropy

and the CfA maintains a useful internal pythonusers mailing list (Tom Aldcroft should be able to point you to it).

Popular posts from this blog

On the Height of J.J. Barea

Dallas Mavericks point guard J.J. Barea standing between two very tall people (from: Picassa user photoasisphoto).

Congrats to the Dallas Mavericks, who beat the Miami Heat tonight in game six to win the NBA championship.

Okay, with that out of the way, just how tall is the busy-footed Maverick point guard J.J. Barea? He's listed as 6-foot on NBA.com, but no one, not even the sports casters, believes that he can possibly be that tall. He looks like a super-fast Hobbit out there. But could that just be relative scaling, with him standing next to a bunch of extremely tall people? People on Yahoo! Answers think so---I know because I've been Google searching "J.J. Barea Height" for the past 15 minutes.

So I decided to find a photo and settle the issue once and for all.

I started by downloading a stock photo of J.J. from NBA.com, which I then loaded into OpenOffice Draw:


I then used the basketball as my metric. Wikipedia states that an NBA basketball is 29.5 inches in circumfe…

Finding Blissful Clarity by Tuning Out

It's been a minute since I've posted here. My last post was back in April, so it has actually been something like 193,000 minutes, but I like how the kids say "it's been a minute," so I'll stick with that.
As I've said before, I use this space to work out the truths in my life. Writing is a valuable way of taking the non-linear jumble of thoughts in my head and linearizing them by putting them down on the page. In short, writing helps me figure things out. However, logical thinking is not the only way of knowing the world. Another way is to recognize, listen to, and trust one's emotions. Yes, emotions are important for figuring things out.
Back in April, when I last posted here, my emotions were largely characterized by fear, sadness, anger, frustration, confusion and despair. I say largely, because this is what I was feeling on large scales; the world outside of my immediate influence. On smaller scales, where my wife, children and friends reside, I…

The Force is strong with this one...

Last night we were reviewing multiplication tables with Owen. The family fired off doublets of numbers and Owen confidently multiplied away. In the middle of the review Owen stopped and said, "I noticed something. 2 times 2 is 4. If you subtract 1 it's 3. That's equal to taking 2 and adding 1, and then taking 2 and subtracting 1, and multiplying. So 1 times 3 is 2 times 2 minus 1."

I have to admit, that I didn't quite get it at first. I asked him to repeat with another number and he did with six: "6 times 6 is 36. 36 minus 1 is 35. That's the same as 6-1 times 6+1, which is 35."

Ummmmm....wait. Huh? Lemme see...oh. OH! WOW! Owen figured out

\begin{equation}
x^2 - 1 = (x - 1) (x +1)
\end{equation}

So $6 \times 8 = 7 \times 7 - 1 = (7-1) (7+1) = 48$. That's actually pretty handy!

You can see it in the image above. Look at the elements perpendicular to the diagonal. There's 48 bracketing 49, 35 bracketing 36, etc... After a bit more thought we…