“Flawless victory.”
March 5, 2008 by fosco
Nerd alert.
I am, professionally, a Unix systems administrator in recovery. By which I mean that I’ve gotten away from day-to-day operational support and have moved (upwards, I hope) into various management roles which are nevertheless still firmly rooted in the technical world. This was a conscious decision, made after the last holiday had been ruined by a series of weekend and overnight support issues. It has proven to be The Right Thing to do. For nearly a year, I’ve been pager-free and have managed to regain all of my leisure and weekend time worry-free. I have, however, also given up the day-to-day control of nuts and bolts. This has been a mixed blessing. On the one hand, well, see above regarding my spare time. On the other hand, the control freak within has had a hard time with the need to futz around with things.
As a sort of compromise, I still try to keep my technical feet wet. Lately, I’ve been taking another look at python. I have a friend (and former co-worker) who is completely gonzo for it, and had been after me for some time to make the switch from perl, which I’d occasionally used for writing quick tools in the course of my work.
He was right. In just a very short while, I’ve come to see that this:
import httplib, urllib, sys
httplib.HTTPConnection.debuglevel = 1
print (urllib.urlopen(sys.argv[1]).read())
is a whole hell of a lot easier than:
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $ARGV[0]);
my $res = $ua->request($req);
if ($res->is_success) {
print $res->as_string;
}
else {
print “Failed: “, $res->status_line, “\n”;
}
Yes, I realize that the perl people will remind me that TMTOWTDI, and here’s a one-liner that accomplishes the same, etc, etc. The one-liner will look like modem noise. I am not a developer, but turned straight to to the network/http section of Dive Into Python and wrote that little three-liner above after studying the examples and looking at the standard documentation. It’s all built right in. Would you like to print out the first 25 Fibonacci numbers?
a,b = 0,1
print a
for n in range(25):
print b
a,b = b, a+b
WordPress is squashing my leading whitespace; the stuff under the for should be indented. Here’s the same code (more or less) in perl. For morans like me, python wins.




