Archive for the ‘Python’ Category

iPython with virtualenv 1

You’ll find a bunch of different approaches to this on Google; Using an iPython boot script that extends sys.path with paths from the current virtualenv. Or calling the iPython script with the virtualenv’s python binary (python `which ipython`). They all tend to be problematic; for example, the latter doesn’t work if the virtualenv has been [...]

Python argparse: Combine nargs=* with subparsers 0

Say you set up argparse with a nargs=’*’ or nargs=’+’ argument first, followed by a subparser to handle a command: parser = argparse.ArgumentParser() parser.add_argument(‘–items’, nargs=’+', default=[]) subparsers = parser.add_subparsers() subparser.add_parser(‘foo’) subparser.add_parser(‘bar’) The usage would look like this: usage: script.py [--items ITEM [ITEM ...]] {foo,bar} This is actually somewhat problematic. If you were to parse the [...]

Python Standalone Packager 0

I need them so infrequently, I forget what different projects are out there: py2exe (Windows only) cx_freeze (cross-platform) py2app (Mac only) pyinstaller (cross-platform) bbfreeze (cross-platform)

Twisted Twistd Autoreload 0

While working on the Twisted server for A World Of Photo, I quickly began missing the convenience of having it automatically restart during development when I had made changes to the code. It turns out that the autoreload module that Django uses is actually pretty generic [1]. One thing Twisted doesn’t like is that the [...]

Opening IRIs in Python 2

As I mentioned on Twitter a couple days ago (Yes, I’ve finally surrendered), I was surprised to find that Python’s urllib/urllib2 refused to open the unicode url I gave it. Then I realized I didn’t actually understand how precisily the non-ascii url stuff even worked, so I decided to change that. Apparently, a URI is [...]

FeedPlatform 0

Looking at my sort-of-todo list, I see at least 4 projects that either need or would greatly benefit from a feed aggregator-like functionality, e.g. not just simply parsing, but updating a list of feeds and keeping track of the items. So it’s seems clear that the right thing to do is to implement this only [...]

SmartInspect Python Logging Client 3

Back when I was still writing a lot of Win32 apps in Delphi, one of my favorite tools was Smart Inspect, a very nice logging tool that also ships with Java und .NET libraries. Unfortunately, I never got to use it that much, since shortly after I bought it I started to drift more and [...]

Sending binary data through stdout on Windows 0

It looks like I’m not the first one stumbling over this, but I just had a lot of fun trying to figure out why a moderately complex binary protocol sometimes randomly failed to work when sent through a subprocess stdout pipe. Apparently, because Python opens Windows stdout in text mode, something like “\x0A” ended up [...]

‘module’ object has no attribute ‘__path__’ 1

If you’re seeing the above error, possibly during a reverse() call, and possibly involving the django.contrib.auth.views.template_detail view, make sure none of your application directories has a file named templatetags.py – Django actually requires this to be be a package/directory. Oh, and on a more general note: Not forgetting the .pyc files when deleting modules will [...]

Debugging Storm queries 0

Storm does not have a query log like you might know from Django. Not to my knowledge at least, the docs are still lacking. If you need to know what queries are executed, you can do: from storm import database database.DEBUG = True This will print all statements to stdout. If you need more, I [...]