#1
try:
do_stuff()
except:
etype, val, tb = sys.exc_info()
raise etype, "%s (%s)" % (val, "happened in the context of X"), tb
#2
class UsedToBeADict(object):
foobar = make_foobar('with sugar'),
bazbar = 1
fezbar = 2
If you don't see the mistakes already, here are some hints...
- #1
- Hmm, I'm looking at the constructor of
exceptions.SQLError, which the traceback led me to, and it is getting 3 arguments just like it should, but why am I getting an error saying there aren't enough arguments?!
- Hmm, I'm looking at the constructor of
- #2
- ok, wtf, why is
UsedToBeADict.foobara tuple??! I'm looking at the return value ofmake_foobar()and it is definitely not a tuple!
- ok, wtf, why is

Re: 2 stupid things I coded this week
posted by Doug Napoleone on Friday Feb 9th, 2007 at 11:42a.m.
#1:
You are only passing two arguments to it, the etype is SQLError, so you are only passing in two arguments, the string and the traceback.
#2:
Comma after make_foobar(), <-- oops, tuple!
Re: 2 stupid things I coded this week
posted by Nea on Friday Feb 9th, 2007 at 1:14p.m.
Hehe cool, I've seen both of the errors - But I have to admit, I've just read about the #2 in the doc a few days ago ;-)
Re: 2 stupid things I coded this week
posted by Kumar McMillan on Friday Feb 9th, 2007 at 1:50p.m.
hehe. yes, both were head scratchers, but #2 probably only because I'd been coding without a break for too long ;) The #1 is very dangerous and I can't believe I ever thought it was a good idea. The traceback basically tells you the wrong thing, heh, since you lose the context were etype is re-raised. I've slapped my own wrists for this and now am always doing:
raise NewException("%s: %s (in context of X) % (etype.__name__, val)), None, tb
Re: 2 stupid things I coded this week
posted by Robin Munn on Friday Feb 9th, 2007 at 1:51p.m.
I've *coded* error #2 -- and recently, too. Kind of embarassing once I realized what I'd done. :-)
P.S. At the "Are you human?" question, I tried to answer "Only after I've had my morning caffeine", just to see what the software would do. Was kind of disappointed when it only let me type 3 letters. :-)
Re: 2 stupid things I coded this week
posted by Kumar McMillan on Friday Feb 9th, 2007 at 2:03p.m.
ha! ok, I'll change that. So far it's fooled the spam bots (knock on wood).
I really hate getting a squiggly captcha that's impossible to read, then hitting submit and getting bounced back to the start by some incompetent web form. sigh, Internet.
Can I gripe for a minute about how americanexpress.com doesn't work in Safari or Firefox? I get a popup everytime about how they don't have my correct email but it's broken and won't let me enter in the new one! grrrr.
Re: 2 stupid things I coded this week
posted by Doug Napoleone on Friday Feb 9th, 2007 at 9:07p.m.
I cant find the post at the moment, but I saw a great writeup on non-captcha solutions. The best I have found in practice is also the simplest.
Have an input inside two div's (important).
The top level div has a class, the inner has an id. [div class="foo"] [div id=bar] [input name="random value"/] [/div][/div]
Then add the css: .foo #bar { display: none }
If you see any data in that field, it's a bot.
This keeps your form clean, and 99% of the bots out.
The class/id trick is done because some bots do some simple CSS checks (usually first order) to see if the element is really hidden. You can also add some javascript, but that will break for clients who have JS turned off.
Re: 2 stupid things I coded this week
posted by Nicola Larosa on Saturday Feb 10th, 2007 at 10:02a.m.
Robin:
> I've *coded* error #2 -- and recently, too. Kind
> of embarassing once I realized what I'd done. :-)
Not at all. I made it too a number of times, and certainly don't blame myself for it.
The fact that a small, practically invisible comma, without parentheses, is enough to define a tuple is a mistake, in my opinion. I would gladly change it in Python 3.0, but our BDFL does not think so. :-|