I lurk in #python. It gets a lot of questions that are, shall we say, frequently asked. This is my attempt to catalogue interesting and useful questions. The answers will gradually become separate postsâperhaps on other blogs if someone else gets to them first. Let me know if there should be other questions, if the answers are unclear, or the answers have bugs in them!
Tagged: python
Pyramid traversal: almost useful
Python needs more software
Consider this a companion article.
I love Python. Itâs healthy and thriving and attracts a lot of clever people. It has its warts, but theyâre mostly manageable.
Unfortunately, it still strikes me as a bit invisible. I havenât really been able to articulate why, but after reading a bunch of those Perl blogs that bring up CPAN, I think it might actually be the software.
For example: thereâs no good Python forum software. Iâm sure there are some bits and pieces here and there, but nothing thatâs attractive, feature-rich, and easy to deploy. That last one is a bitch, I know, but itâs important. Right now, if I want to throw up a forum, my viable options are really phpBB, vBulletin, and some other crappy PHP things. I think MyBB might be Perl, but who even uses that?
Gotcha: Python, scoping, and closures
Iâve touched on this kind of thing before, but I just saw it come up again, and I think itâs worth its own post not buried in an avalanche of armchair psychology. Plus, I remembered that Blogofile does syntax highlighting.
Closures in a loop
If youâve been linked here, youâve probably complained that this doesnât work as you expect:
1funcs = []
2for i in range(4):
3 def f():
4 print i
5 funcs.append(f)
6
7for f in funcs:
8 f()
The output will be 3
, repeated four times. Gasp! Python is totally broken! It doesnât support closures!
Well, no. Python supports closures all too well, and thatâs causing the problem here. The issue is with scoping.
Architectural Fallacies
I spend a lot of time in #python and #perl. Far more than is healthy, probably. And Iâve noticed some patterns in the kinds of questions people ask.
There are plenty of people who have trouble expressing themselves well enough to get answers in the first place, but those are just communication problems. (Thatâs a good read if you ever ask nerds for help, by the way.) More subtle, more insidious, and more common are people who just ask questions that shouldnât be asked in the first place.
These are architectural fallacies: logical flaws in the very process of building or designing something. They lead programmers towards solutions that are hard to understand, are inefficient, or just donât work. And they confuse the heck out of the people trying to help.