Wandering Thoughts archives

2006-06-05

A Python coding mistake

There is a world of difference between '"string" in txt' and just '"string"'. It doesn't even really jump out as visually wrong to me if it's in a large if condition, which probably means the condition is big enough that it should be reorganized so that errors are more obvious, or at least harder to make.

(Repetitive code is especially prone to this sort of slip-up for me. Unfortunately, one of my bad coding habits is quietly growing into such code by accident.)

Interestingly enough, pychecker doesn't produce any warnings for this. This isn't its fault as such; although it tries to look for them, it works from the compiled bytecodes and since Python 2.3, the bytecode compiler optimizes away the constant conditions.

Pylint didn't detect it either, although it complained about a lot of other things by default (enough that I can't imagine using it on a real project, especially since I use tabs for indentation).

(This exact mistake accidentally shut down commenting here for about half a day. My apologies to anyone caught in the accident, which would have given peculiar error messages.)

PythonCodingMistakeII written at 16:50:51; Add Comment

By day for June 2006: 2 5 19 24 26; before June; after June.

Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.