News You Can Bruise

Permalink [Comments] (1) :

CherryPy for CGI Programmers, my third DeveloperWorks article, is published. I didn't get a chance to go through it for last-minute errors because I was coughing up blood--the blood of being incredibly lazy! So now I'm afraid to look at it.

Incidentally, if you want to make money writing, articles are where the money is at, not books. I made about 75% of my Python book advance writing those three articles, and it took me about 10% of the time. Plus my book advance still only exists in potentia, whereas I've already gotten and spent my article money.

Not feelin' good. Not gonna take it out on you.

technology/languages/python

Permalink [No comments] :

Done with the Cheetah article. Good to know I can still put these things off until the last minute.

technology/languages/python

Permalink [Comments] (3) Socket Question:

Okay, here's something interesting. Python's socket documentation for the socket.shutdown method mentions three constants: SHUT_RD, SHUT_WR, and SHUT_RDWR. However, nowhere I can find does Python actually define these constants. It's obvious what they are because they're ripped off from C/Unix constants of the same names, and those always start numbered from zero. But it seems really weird that the socket library would forget to define these constants even though it defines a million other constants. Am I missing someplace where those constants are defined?

technology/languages/python

Permalink [Comments] (1) Amazing!:

Python shipped with DVD player! Uh, don't read the rest of that headline.

technology/languages/python headlines

Permalink [No comments] :

File-sharing is the new encryption.

technology/languages/python

Permalink [Comments] (3) :

I don't know why I could find no Python library equivalent of The Demoronizer, but today I got fed up with not just Microsoft smart quotes but with ISO-Latin-1 in general, and I wrote ASCII, Dammit, which will remove those characters from your string once and for all, replacing them with HTML encoded entities or with my lame guess at a plain-ASCII rendering.

I'm sure there's something you're supposed to do ahead of time to prevent Python from choking on those characters, and that I'll hear all about it soon, but this is still useful because you can use it to get rid of the Microsoft smart quotes. Everyone hates Microsoft smart quotes, right?

development/NewsBruiser technology/languages/python technology/languages

Permalink [No comments] Obsessive Beautiful Soup Press Watch:

Beautiful Soup got a footnote link in this PyZine tutorial about retrieving web pages in Python, and the 1.2 release was linked to from the Daily Python-URL. The 1.2 release is pretty old, actually, but it just got added to the prestigous Vaults of Parnassus so they probably picked it up from there.

I'm actually a little frightened of the mysterious way Daily Python-URL chooses what to link to. For instance they linked to this back in January even though it was just a random observation about Python and not, in my opinion, worthy of being linked to. I feel like I should put disclaimers in my non-weighty Python entries ahead of time. Don't link to this entry, Daily Python-URL! Link to that PyZine tutorial instead. It's cooler than this rather obsessive post.

technology/languages/python

Permalink [No comments] Predigested Meaning:

uselessword and 0x800ccc0d are... well, they are what they are. I really like the idea of replacing words with random numbers; the result looks like someone should be reading it over an obscure radio band.

Incidentally, you can do base conversion in Python by passing in the base as the second argument to the int() function. Pretty neat, huh?

math technology/languages/python

Permalink [Comments] (3) Software Endorsement:

If you're writing a database application in Python and you need a object-relational mapping (ie if you're writing a nontrivial database application in Python), I recommend SQLObject, written by NYCB reader Ian Bicking. I tried most of the ones on this list and SQLObject was the least frustrating of the lot. NOW YOU KNOW.

technology/languages/python

Permalink [Comments] (4) One Piece At A Time:

There's lots of Python code that pings weblogs.com, but I couldn't find a Python library for the other side of the equation; one that parses the big XML file of recent pings. That's why I developed the Ass-Kicking Laser Algorithm, which does that very thing. Even with the paucity of things you could conceivably do with the weblogs.com XML file, I think it has more options than are wise. Once I start actually using it I may trim it down. But like I say, one piece at a time.

The name is Kris'. He came up with it in 1998 when I was complaining that the algorithms I was learning about in class didn't live up to their cool names, like the gift wrapping algorithm and Graham's Scan. Since any interesting name I could give this library would set the user up for an anticlimax, I figured I'd go all the way. Thanks, Kris.

In retrospect, though, Graham's Scan is pretty cool.

development technology/languages/python people/Kristofer Straub

Permalink [Comments] (1) :

Guido Van Rossum: Vengeance

technology/languages/python

Permalink [Comments] (2) Python Question:

Is there a Python library that's like the standard time library, except it can handle dates before 1900? It's not for myself that I ask; it's for a friend. Guido mocks his pain. Can't you help?

technology/languages/python

Permalink [No comments] :

A more tech-oriented entry to close off WikiDay (unless you or I can think of something else). Let's say you really like buzzwords (specifically, the same buzzwords I really like). Well, check out my ex-co-worker Greg Stein (now at Google)'s SubWiki, which combines "Wiki", "Python", and "Subversion" in pleasing ways. Is there any interest, or indeed any conceivable need, for me hosting a Wiki on crummy.com?

PS: If you know of any cool Wikis, post them in comments.

technology/software technology/languages/python

Permalink [Comments] (5) :

Can someone point me to an HTML parser that turns an HTML document into a nested data structure like what I sketched out below? I'm sick of having to jump through hoops to collect the text of a link. I know there's something similar for XML because I heard about it at EuroPython. Stop me before I write my own! Must work or be makable to work in Python 1.5.2. Offer not valid in "Mirror, Mirror" universe.

Sorry, no spectacular thing to show you today. I've got only one of the three things working that I wanted to have, and (sad to say) it's not the one that hits people in the gut and makes them think This Is Important, insofar as any of them do that.

This is an HTML document.

->

["This is an", [TAG name='a' attrs={href: 'http://www.w3.org/MarkUp/', title: "Brought to you by HTMLCorp"} child=[TAG name='b' child=["HTML"]], "document"], "."]

Update, much later: I wrote Beautiful Soup because I wasn't happy with any existing parser.

development site-meta/Best Of NYCB technology/languages/python

Permalink [No comments] Helpful Python Tip:

The parser in the htmllib library is useless for actually parsing HTML. Use the one in sgmllib instead. I learned this once when writing the Eater of Meaning and I'm learning it again with this new project I'm working on. Hopefully I'll have something to show you tonight.

development technology/languages/python

Permalink [Comments] (7) Great Things About Python #1:

The way you can unroll an arbitrarily complex data structure deeply nested list in a for statement, and assign everything to variables, and it's readable.

Update: I don't think this entry deserves to be on the Daily Python-URL, but I'll take what I can get.

technology/languages/python

Permalink [Comments] (2) The Film Goes Ever On And On:

Saw Return of the King today. Great stuff! (Despite the lack of all of my favorite scenes.) I felt sorry for the mumakil, though. They were only trying to have fun! Stomping on people.

PS: Hey, Past Leonard, you saw The Two Towers with your family and Return of the King with the rest of the technical team from the presidential campaign where you work.

Past Leonard: Yeah, right. Stop calling me here!

Anyway, I see that Saruman has not been idle since the War of the Ring: his love of perverting all that is good and natural is surely the driving force behind Perlthon. Look at the author's name! "Manura"? An obvious anagram.

Future Leonard: Hey, Present Leonard, you will watch the extended DVD version of LOTR to pass the time on your colony ship's voyage to Sirius.

Stop wasting my time!

film technology/software technology/languages/python

Permalink [No comments] "Shut down the ENIAC.":

I thought this joke Python proposal was pretty funny. So funny, in fact, that I already linked to it. Note to self: replace this entry with something new.

OK, here you go. Resign Patterns, including "Simpleton" and "Flypaper". From Ned Batchelder's weblog.

weblogs technology/software technology/languages/python

Permalink [No comments] :

A funny Python proposal. It drags a bit in the middle, but the payoff is good.

technology/languages/python

Permalink [No comments] :

A nice Python interface to the timezone database. Requires Python 2.3.

technology/languages/python

Permalink [No comments] :

Jarno: "Stop Promoting Python" was a joke talk. The premise was that promoting Python would lead to the existence of more Python programmers, which would impair the abililty of the preexisting Python programmers to charge high fees for their services. The conclusion was that Python programmers should contrive to keep Python a secret so as to mantain a competitive advantage relative to Java programmers. This, you'll recall, is the strategy that has worked so well for Lisp.

technology/languages/python technology/languages

Permalink [No comments] :

For the impatient, Jarno has information about EuroPython and the surrounding vacation: 1 2 3

weblogs technology/languages/python

Permalink [No comments] EuroPython Day 3:

Yesterday, Guido had a keynote which was different enough from his PyCon keynote that I stayed interested. I just came back from a talk on SQLObject, a simple object model/database layer. My head is spinning after a number of rapid-fire Twisted tutorials. Also I learned about empy, which I had previously not looked at due to it being GPLed. It looks very nice, so I may put effort into resolving the license incompatibility somehow. There was also a mention of Jeff Raskin's The Humane Editor (not The Human Editor), which does for commenting syntax what Python did for control flow syntax.

At dinner last night I had an ice cream dessert, like a giant Mochi, called a "Tartouffe". I do not know anything about it or why it is named after a Moliere character, but it was tasty.

food technology/languages/python

Permalink [No comments] EuroPython Day #2:

My French is getting a little better; at least it seems that way now that I've met people whose English is worse than my French, such that it's most convenient to talk in French. I was able to ask for the check and to have a door opened, although the check was not forthcoming and the person I asked was powerless to open the door. My presentation went pretty well, but I'm very glad I omitted the jokes because the one I left in, thinking it had cross-cultural appeal, was not greeted with any hilarity at all.

I talked with Moshe Zadka a bit after my talk. I talked to some other people as well but I bring up Moshe because there were several talks he was going to give yesterday but he didn't get here in time. These include his "text steganography" talk and his "Writing web clients in Python" talk. I've asked him for copies of the notes for each, and they'll be part of the inevitable EuroPython roundup, coming sometime next week to this space. I was able briefly to recharge my battery, but it's only at 50% and I want to write another rambling, incomprehensible entry tomorrow, so I'll sign off now.

Best talk so far: a talk about PyPy, a Python interpreter written in Python, which is currently up to 20,000 times slower than the one written in C. Armin Rigo, author of PyPy, also wrote his own presentation softwareusing PyGame, which presented his presentation as a brainstorm diagram that he navigated as he gave his talk. It's only a matter of time until Steve Jobs steals that idea.

technology/languages/python technology/languages

Permalink [No comments] Hello:

I'm at EuroPython, squandering my precious laptop battery power that I need for my presentation tomorrow. I bought a wide variety of adapters and power convertors but they're all useless because my laptop won't plug into them due to its grounding plug. Fortunately, I'm supposedly about to meet up with someone who has an IBM power cord with a European connector.

I went to Amsterdam. I've been hanging out a lot with Jarno and his girlfriend PrustiTaina, because their travel plans have overlapped with mine to an unbelievable extent (eg. they planned to go to Amsterdam the same day I planned to, they chose the same hotels that I did, etc.) I also ate a waffle. My French is only good for reading and not for hearing what people are saying, nor for talking because when I try to talk to someone in French they just respond in English.

food technology/languages/python people technology/languages places

Permalink [No comments] Aiee:

I don't know if a European audience will get the jokes in my Europython configuration talk (not all jokes present in the online version). Eg. do Europeans know enough about Godzilla that they will realize my little Godzilla skit is a) a skit, and b) funny? I need new jokes. Maybe I should just do without jokes, or come up with them while in Belgium.

Also, what has the same sort of semiarbitrary, dependency-ridden semantics as a ZIP code, but Europeans know what it is?

biology/organisms/kaiju/godzilla technology/languages/python

Permalink [No comments] J'irai au EuroPython:

I've mentioned this before, but I want to bring it to the attention of more people, particularly pyblagg readers. I'm going to EuroPython later this month (to give my neighborhood-famous "Beyond The Config File" talk), and I want to hang out with people. Drop me a line if you're also going and you want to meet up.

technology/languages/python

Permalink [No comments] :

First, let me shill again for pyblagg, which helps me find so much cool stuff that I don't even care that I'm hopelessly behind on Software Roundup. First, a 1998 paper called on reuse called The Selfish Class, which tickles my buttons (the low-key version of "pushes my buttons"). I'm not sure how much of it is an eloquent statement of things I already knew and how much of it is actual new ideas that just sound very familiar; it seems each section starts with the latter and concludes with the former.

Then there's the awesome ezPyCrypto, a GPLed (so beware)library which makes it incredibly easy to do crypto in Python. Encrypt everything, just because you can! Encrypt your own source code in some sort of obfuscation/trusted computing thing! Encrypt the very name of your program! Encrypt your cat!

technology/software technology/languages/python

Permalink [No comments] Woohoo! La Deuxieme Partie:

I'm going to give my configuration framework talk at EuroPython! It's in Charleroi, Belgium, and it looks like the easiest way to get there is to fly into Brussels and take the train. Charleroi is in the south of Belgium, so I should brush up my French (call me provincial, but I'm not going to learn DutchFlemish for a one-week trip to the part of Belgium where they don't speak DutchFlemish). What's the best way to regain lost fluency in a language?

technology/languages/python technology/languages

Permalink [No comments] The Unit Price:

So, with that spot of unpleasantness out of the way, we're free to talk about the really exciting thing: unit tests! I wrote the Eater because I like writing that sort of thing, but also to get into the habit of writing unit tests. Here are my observations on the process:

Before you write code, you're supposed to write unit tests. It turns out I can bring myself to do this most of the time, but I do it grudgingly because I don't like writing the infrastructure for a new type of test. The way I generally do it is to write the tests but leave the expected value for the assertions blank (unless the expected value is really easy to figure out, or is actually defined and not just the result of applying some transform to some data I just made up). Then I write the code and all the assertions fail. I use the code I wrote to figure out what the asserted values should be, fixing bugs as I do, and paste in the final, correct values for later use.

Where unit tests are really great is when you find a bug in your code. If you've put in the work to write that infrastructure for that sort of bug, it's easy to record your finding of the bug in a way that will automatically notify you if it ever shows up again. This is lesson one: unit tests give you a place to codify the results of the debugging process. By putting in some incremental effort you can ensure that you're notified should the bug you're fixing ever recur. Usually it doesn't recur, but your real worry is not the bug recurring; it's the bug recurring without your knowledge. With unit tests, you know.

Sometimes when I refactor code I worry that some portion of the code I never exercise has broken due to refactoring. This is the worst thing about Python: unless you're using Leo (which I'm still not, despite my earlier touting of it), when you refactor the code the indentation changes, and when that happens you have to redo the indentation because the automatic indenter never works right, and all sorts of problems can crop up.[0] Unit tests find the problems, and if there are any you fix them and that's that. Lesson two: with unit tests, instead of worrying about code you broke while refactoring, your mind is free to worry about less rational things, like bloodthirsty packs of feral hamsters roaming the streets.

I have unit tests for all my Eaters, and some decent coverage for the HTML parser, but nothing yet for the user interface (even though I wrote the user interface to be drivable from Python code) or the thing that grabs URLs. This is because of lesson three: the closer a piece of code is to an actual user, a piece of hardware, or data from the outside world, the more aggravating it is to write unit tests for it. I am convinced this demonstrates a close affinity between unit tests and Lisp.

The big wrapper lesson is that unit tests are a way of creating a grammar with which to describe the behavior of the system so that you can offload to the computer the task of checking that behavior. Unit tests are easier to write when the elements of the grammar have simple APIs that you control, and harder to write when the elements are complex things with outside dependencies, like URLs and mouse movements. Even if you only write unit tests for the simple stuff, it means your agonizing over the more complicated stuff will be untroubled by the suspicion that the problem is something lower-level and simple (of course, then it turns out to actually be something lower-level and simple, and the code says "Gotcha!" like Lucky Ducky and struts off, but I can't help you there).

[0] Eventually I'm going to write my own autoindenting Emacs hook which operates on the very simple principle of moving the cursor line to where autoindent takes it, then moving every child line left or right the same number of spaces. I don't know why other indenters have these fancy algorithms that don't work, when that algorithm works fine. With my algorithm you have to go down arbitrarily many lines before moving the first line, to see how many lines are underneath the first one, then go back up to the top and go through all those lines again, but on the plus side it actually works.

development technology/software technology/languages/python

Permalink [No comments] They Have Blogs:

He's a Python programmer. She's... also a Python programmer. They have blogs! Also available as one huge barely-differentiated group weblog.

(PS: format taken from They Have Blogs, a web toy of about a year ago).

weblogs technology/languages/python

Permalink [No comments] Suffertime:

I forgot to mention that another thing I don't like about template systems is when they add whitespace to my template as they interpolate it. I'm going to be using this templating system to generate RSS 3.0 feeds and other things that care about whitespace. I finally got XYAPTU to work in 1.5, but it introduces blank lines and extra spaces all over the place until I can't stand up. Bleah. Still hacking. Update: Got it to work.

development/NewsBruiser technology/languages/python

Permalink [No comments] Python Templating System Roundup:

[From time to time, "Software Roundup" will appear in a bonus edition, evaluating according to obscure criteria the members of an overly bifurcated software category. Only Crummy Premium subscribers ($24.95/year) will be spared this exclusive content.]

I'm investigating Python templating systems for use in NewsBruiser. TTM!'s functional approach is good for user-entered templates that fit into predefined control flow, but I'm looking to start doing the screens with templates, and it's no good for that.

By my side-of-the-envelope calculation, there are more Python templating systems than there are Rocks 'n' Diamonds levels. I've skimmed some web pages and tried to get a few of them to work, so I am now an expert on Python templating systems, at least as regards whether or not I can use them in NewsBruiser.

Here are my showstoppers for any module I might want to incorporate into NewsBruiser. The first two are born of my design goal of making NewsBruiser work for anyone whose hosting service has Python available and who can unzip a tarball. The last one is due to the unfortunate reality of software licensing. I've looked at the template systems with these showstoppers in mind, which means that often I'll simply dismiss a possibly deserving module without really looking at it; this is not a reflection on the module.

First, the ones I can't or won't use:

[STOP PRESS! Crummy Premium subscription now only $24.91/year! Such a deal!]

Now, the actual contenders:

So, unless I find something else that's better (do you know of any?), or I can get XYAPTU to work, I'm probably going to hack up AHTS or tinpy to fit my needs.

technology/languages/python technology/software/roundup

Permalink [No comments] World Famous Leonard:

Mentioned in Linux Journal!

technology/languages/python

Permalink [No comments] CrummyTone News Presents: The March Of PyCon:

My PyCon report is up. It's got notes on all the talks I attended, a lot of links to useful software (it's basically a very verbose and Python-specific Software Roundup), and random ramblings about Washington D.C.

technology/software technology/languages/python technology/software/roundup

Permalink [No comments] Two Great Tastes Dept.:

Lucene got ported to Python.

technology/languages/python

Permalink [No comments] PyCon Talks I Wish Had Existed:

technology/languages/python

Permalink [No comments] :

Easibox looks to replace the little shell script I have written to tar up NewsBruiser releases. I'll have to hack it to pregenerate the template for the release message, though.

development/NewsBruiser technology/languages/python

Permalink [No comments] 100% Pure Adrenaline!:

Here are my PyCon slides.

technology/languages/python

Permalink [No comments] :

I put up my PyCon paper and the sample applications. I'll put up the slides tomorrow (they're on my laptop, which is at work).

technology/languages/python

Permalink [No comments] :

I skipped out of PyCon after lunch and did tourist stuff. I recommend the new Korean War memorial, and the Burgess Shale fossils in the Natural History Museum.

I forgot to mention my talk. It went well. I'll link to everything when I get back, and mention all the other interesting things seen at PyCon (including the presentation that compelled Guido van Rossum to say, "I don't think our insurance covers this.").

technology/languages/python

Permalink [No comments] :

Hey, remember Grail?

technology/software technology/languages/python

Permalink [No comments] Not-So-Eternal Recurrence:

Four years ago I wrote three programs in three different languages (Perl, Java, and awk, I think it was). Today I wrote the same program three different times, in progressively less hacky ways. I call this the "three stages of App", and it's the best lead-in I can think of to the topic of configuration interfaces.

technology/languages/python

Permalink [No comments] Woohoo!:

My PyCon presentation was accepted!

technology/languages/python

Permalink [No comments] :

Behold the Four Noble Truths of Python! "All that is not Python is Suffering."

technology/languages/python

Permalink [No comments] Leo:

I'm looking at Leo, an outline editor written in Python and Tk which is supposed to help you do literate programming. I saw people being fanatics about it on some wiki, and since for a while I've been looking for an outline editor I figured I'd give it a try. I'm using it to organize things like my to-do list and my start page. Time will tell whether it's useful for mantaining documents, but it looks like it will be: I imported a NewsBruiser code file and got a very coherent view of the code.

At the very least, Leo is the outline editor I've been looking for, and I can pretend to be one of those people, like Joseph Allen, who uses an editor named after them. At most, I will become one of those people who is a fanatic about Leo on wikis.

Note: I had to recompile Python to get Leo to work, because my preinstalled Python defined Py_UNICODE as wchar_t even though wchar_t on my system is 32 bits, in direct contradiction to what The Python/C API Reference Manual says. I mean, geez.

technology/software technology/languages/python

Permalink [No comments] Another NewsBruiser Competitor:

Spyblog ("Simple Python blogger"). It's got comments!

weblogs technology/software technology/languages/python

Permalink [No comments] A Thought:

Sometimes you can tell that a mailing list uses a Python script to generate its copy, because the mail merges have spaces after them, eg. "Hello, Leonard ,".

technology/languages/python

Permalink [No comments] :

Most of the slogans in the Maoist Python poster weren't revolutionary enough, so I made it more suitable to the Peoples' taste. Remember: you never saw the previous version.

technology/languages/python

Permalink [No comments] :

Comrades! Hear the wise Chairman's words on carpal tunnel syndrome!

technology/languages/python

Permalink [No comments] :

Whenever people find out that I like Python, they always ask me the same question: "Is that your real hair?" No, wait, that's not the question. The question is "Don't the whitespace restrictions cramp your style?" THE ANSWER IS NO. It's something which you get used to. Every language has such things, and at least Python's whitespace restrictions serve a useful purpose. By the way, you know what bugs me about Perl? The damn brace restrictions! Every time you want to do any kind of conditional, you have to type a curly brace. Then you have to match it up when the conditional is done. C and Java have this problem too.

technology/languages/python