php to eat, python to grow!

Just saw this gem on reddit: http://www.reddit.com/r/Python/comments/9pd33/dear_redditpy_could_you_help_me_convince_myself/c0dt5wa

Also, good luck on implementing an http-proxy in PHP, the damn thing would have to be huge, ugly and would require at least one PEAR lib to do it the right way.

And for some reason wordpress post by e-mail has a low google ranking, so I thought I should +1 that. Though I personally prefer a clunky interface to an ajax one any day.

Standard library granularity in python, argparse vs getopt

Is it ok that python has 2 modules for option parsing, 3-4 xml packages, 3 HTTPServer modules, etc? This issue hit me when contemplating the deprecation of getopt as a part of the inclusion of argparse. Whenever I want to parse xml/html I get overwhelmed by the options in the std-lib. I remember myself annoyed and confused by getopt/optparse both showing me 2 different ways of doing something so similar. As a newcomer to python, I wanted python to show me the right way of doing things.

So following that line of thought, getopt is the ugly way of doing option parsing. It imitates an option parsing flow that came from the old C days (and thus unpythonic), making it very attractive for people familiar with getopt/xgetopt. So what’s more important: easy learning curve or enforcing best practices?

I wanted to see how ugly getopt code looks so using google code search I found a few real life usage examples.

getopt sample code, or check out the search results yourself:

optparse sample code:

At first I thought the learning curve thing was important, but in the end, getopt is a very unpythonic module that I would rather not see any of my colleagues use at all, except for rare cases where an awful lot of flexibility is needed. For example, getopt could be an easy way to implement optparse, or a completely different alternative. For example pyopt uses getopt in such a way. So IMHO getopt should be in the std-lib, but the documentation should have a very big sign saying “use the awesome optparse/argparse, this is a very simple parser with barely any of the features you probably need”.

Where’s toString?

Why don’t python integers have a smart toString method like java/javascript? It’s easy to convert strings into numbers using int(str_whatever) or float(str_whatever) but to convert them back you have only the decimal system (using str(number) or “%d” % number). In case you want to convert to binary, base32, base36, base64, you’re gonna have to write your own conversion function. Batteries included?

Use either:
http://pastebin.com/f54dd69d6

http://code.activestate.com/recipes/65212/

http://code.activestate.com/recipes/111286/

I added a feature request, lets see if it gets completely shot down:

http://bugs.python.org/issue6783

What python lacks

I do like python a lot, but I feel some things are still missing. Correct me if I’m wrong.

* How do I know what can I import? I can use help(os) but how do I know that ‘os’ exists (from within the interpreter). I want a command like dir that can search through the default import directories. “mdir” (like module dir) or “pdir” (package dir).
* Tkinter sucks, why isn’t wx or anything else included?
* The php documentation really makes me jealous because the user contributed comments are VERY useful. Why doesn’t python docs have some web 2.0 in it? Like digg’s comment system.
* So many crappy IDE’s, I can’t find one that’s good for everything. At first I liked Wing but nowadays it’s way too slow and heavy so I switched to SPE which is great except it can crash for no reason.
* The GIL needs to be taken more seriously with a dedicated page explaining why it’s in place, how to escape it’s suckiness, and a roadmap to minimize the damage. Alot of people care about performance more than idiot-proof concurrency.

And I think i have a few more rants to go on about this, I’ll post ’em when I recall.