Python namespacing is the hardest thing for me to get used to so far

Aug 22, 2006

I keep stumbling over the same thing in different contexts: namespacing and how to address particular objects. It’s very context sensitive, and I’m not quite grokking it yet, especially on the ‘pythonic’ way to do it. The documentation is not very clear on a first reading of how to deal with it.

Here’s an example of simple module I just started:

import xml.parsers.expat from xml.dom.minidom import parse, parseStringimport string

class RFRData:   DATA = None

   @classmethod   def get(cls):       
                    if not DATA:           

   @classmethod   def init(cls, conf=None):       

   @classmethod   def load_data(cls, conf=None):       
                      if conf:               
                        if conf.find('

It took me about 15 minutes to find:

  • What module the ExpatError class lived in
  • How to import the module correctly

If I don’t trap the error, and the xml is invalid, I get this message:

ExpatError: mismatched tag: line 21, column 6

Fine, but how to trap it? My expectation, based on that message, would be that I could have this line:

except ExpatError, err:

But no, python reports:

NameError: global name 'ExpatError' is not defined

That won’t work because I only imported a couple methods from the xml.dom.minidom package. So I try…

import xml.dom.minidom[...]except xml.dom.minidom.ExpatError, err:

And no, that doesn’t work, either:

AttributeError: 'module' object has no attribute 'ExpatError'

Which, of course, is correct, because it’s just a dom module, not a parser module. I just tried those two reflexively, based on my expectations.

So, where does ExpatError live? In the xml.parsers.expat module, where one would expect it to live. And I have to import it to trap errors from xml.dom.minidom.parse().

My beef is that:

  • The documentation for xml.dom and xml.dom.minidom don’t mention the need to use xml.parsers.expat directly, nor is it shown in the examples.
  • Python error handling returns an exception object from legitimate code that I can’t reference unless I import an additional package, and it is not clear at all which package I should be importing. It took me a few minutes of looking at the docs to find it this time, but in a difference situation, this type of problem could have stumped me for a while.

Wake me when the anarchists leave

Aug 9, 2006

For about the past six months, I haven’t been very active in the Libertarian Party. I’ve decided to continue that trend.

I don’t feel as if I have a political home. I know there was some major upheaval at the LP National Convention – the pledge was kept, but much of the platform was gutted – that was largely a victory for the “moderates” or “reformers” in the party, at the expense of the “purists.” (I used quotes because I don’t know who is using which terms.) I think that larger schism in the party is between anarchists and minarchists, and has been for a while. The convention may have been a victory for the minarchists, but the anarchists seem to be more galvanized for action.


"Do you believe in Jesus?"

Jul 1, 2006

I stopped off at the grocery store on the way home from work Friday evening to pick up a few things. I was almost done. Milk: check; beer: check; etc. The last thing on my list was chips. I love chips and salsa, especially with beer (see previous ‘check’).


How's the view up there?

Jun 26, 2006

Manager-types like to look at things from a “high level.” Instead of worrying about the crucial details of a project, they prefer to be a bit further off, so they can see issues from multiple angles, and how those issues relate to each other.


Software Wars gets some hits

Jun 8, 2006

I put up my Software Wars Map way back in January, and it pretty much just sat there. In late May, for some reason, I suddenly started getting a several thousand hits per day from StumbleUpon, which is pretty amazing considering my site previously was getting only about 30-50 hits per day, mainly to my SkillMarket page. I don’t know how or why it happened.


On Mainstream Media Bias: Proof That People See What They Want To See

May 29, 2006

I had subscribed to the feeds of both Media Matters and News Busters for a while. These sites purported to document mainstream media bias, from a conservative or liberal angle, respectively. I’ve dropped them both. Why? At the very least, they cancel each other out. But recent posts on each site illustrated the impossibility of “impartially” tracking the bias of the media. I found a particularly clarifying example.