Python namespacing is the hardest thing for me to get used to so far
Aug 22, 2006I 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:
cls.init()
@classmethod def init(cls, conf=None):
cls.load_data(conf)
cls.validate_data()
@classmethod def load_data(cls, conf=None):
try:
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, 2006For 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.
Read more...If I were Darth Vader....[video]
Aug 8, 2006… I’d probably be a lot like this…
Read more..."Do you believe in Jesus?"
Jul 1, 2006I 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’).
Read more...How's the view up there?
Jun 26, 2006Manager-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.
Read more...Software Wars gets slashdotted!
Jun 24, 2006I took a vacatation on Thursday to go to a special charity screening of Serenity. My wife was coordinating the activities of the local showing, so I was gone from early afternoon till late in the evening. Right before bed, I figured I’d check my email – and I found that I’d gotten dozens of emails about The Software Wars Map in my inbox.
Dozens of emails? Had I suddenly gotten a lot of traffic?
Read more...From The Software Wars Mailbag...
Jun 24, 2006I’ve gotten dozens of emails over the past couple days about The Software Wars Map – all of it positive. Many people had suggestions, some had criticisms of a sort, but it was all positive – except for one, single message. I’ve included it below.
Read more...Software Wars gets some hits
Jun 8, 2006I 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.
Read more...On Mainstream Media Bias: Proof That People See What They Want To See
May 29, 2006I 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.
Read more...Word Of The Day: ButFirstification
May 19, 2006It doesn’t mean what you think it means, but it sure is fun to say.
Read more...