All Articles

  1. Hacking mock: Mock.assert_api(...)

    Mock is a great module to use in testing, I use it pretty much all the time. But one thing I have nerver felt great about is the syntax of it's call_args (and call_args_list): it is a 2-tuple of the positional arguments and the keyword arguments, e.g. (('arg1', 'arg2' …

  2. Using lib2to3 in

    It seems that many people think you need distribute if you want to run 2to3 automatically in your But personally I don't like setuptools (aka distribute) and hence don't like forcing this on users. No worries since plain old distutils supports this as well, but it simply appears …

  3. Discovering basestring

    This may seem simple and trivial, but today I discovered the basestring type in Python. It is essentially a base type for str and unicode, which comes in handy when writing isinstance(foo, basestring) in test code for example.

    Strangely, despide PEP 237 mentioning the equivalent for int and long …

  4. Pointer arithmetic in C

    Pointer arithmetic in C is great. The only downside is that it's only defined when pointing to an array (or an item just after the array). That is one giant downside.

    Allocate a chunk of memory and you can't use pointer arithmetic. So if you are building a linked list …

  5. The master plan

    Catherine Devlin describes it very nicely:

    I finally understand Al-Qaeda's master plan, and it's freaking brilliant. [...] I'm just surprised that we're choosing to participate in the plan. I thought we were on opposite sides?
  6. Terminology

    Why was it ever considered desirable to call a directory containing a file a "package" rather then just "module". They are after all simply "modules containing other modules". It's not like that solved some sort of problem was it? But, as sad as that sometimes might be, we …

  7. Installing Debian on a Sun Fire X2200 M2

    Most important thing first: the eLOM console lives on ttyS1 (9600n8). If that gets you going you do not need to read any more.

    This works pretty easily, but there's isn't much information about how this works if you don't like using a keyboard and a screen (having these things …

  8. Decorators specific to a class

    My gut tells me it's horribly wrong but I am failing to formulate a decent argument, let me show an example what I mean (somewhat contrived):

    def deco(f):
        def wrapper(self, *args, **kw):
            with self.lock:
                f(self, *args, **kw)
    class Foo:
        def __init__(self):
            self.lock = threading.Lock …
  9. Calling COM methods in C

    So Windows has this strange thing called COM. It allows you to share objects between unrelated processes and languages, a bit like CORBA in that sense, only very different. Anyway, if you'd like to get information out of this other Windows thing called WMI (which provides a lot of information …

  10. Setting descriptors on modules

    This counts for one of the more crazy things I'd like to do with Python: insert an instance of a descriptor object into the class dict of a module.

    While you can get hold of the module type class by using the __class__ attribute of any module or use types …

  11. Skipping slow test by default in py.test

    If you got a test suite that runs some very slow tests it might be troublesome to run those all the time. There is of course the "-k" option to py.test which allows you to selectively enable only a few tests. But what I really wanted was a way …

  12. setuptools vs distribute

    Reinout van Rees:

    In case you heard of both setuptools and distribute: distribute fully replaces setuptools. Just use distribute. Setuptools is “maintained” (for various historically dubious values of “maintain”) by one person (whom all should applaud for creating the darn thing in the first place, btw!). Distribute is maintained by …
  13. Dictionary entry

    innovative company

    noun 1 a company which can't afford patent lawyers *2 one of the lucky handful companies who are innovative and have money for patent lawyers *HELP Not to be confused with most companies lobying in patent litigation.

    PS: It's also possible to have companies that can't afford patent …

  14. How to drive on a motorway

    If you are driving on a motorway where I am driving too, here are some rules you should follow. I think you should even follow them when I'm not around.

    1. Be sensible, this one overrules all the others
    2. Keep left unless overtaking
  15. How to make a crosslinked RS-232 cable

    Because it's easier then buying one

    When connecting two computes together (e.g. your laptop to a server or router) to get access to a console you need to use a crosslinked RS-232 cable, usually with two female DE-9 connectors these days. This cable is more commonly known as a …

  16. Tuple unpacking goodness

    Todays pleasant surprise:

    >>> a = {'a': (0, 1), 'b': (2, 3)}
    >>> for k, (v1, v2) in a.iteritems():
    ...     print k, v1, v2
    a 0 1
    b 2 3


  17. Synchronous classes in Python

    What I'd like to build is an object that when doing anything with it would first acquire a lock and release it when finished. It's a pattern I use fairly-regularly and I am getting bored of always manually defining a lock next to the other object and manually acquiring and …

  18. Python modules and the GPL: I still don't get it

    I've never understood if you can use GPL python modules (or packages) in GPL-incompatibly licensed code. Today I re-read the GPL looking for this and am tempted to think yes, you can. The GPL says:

    1. You may copy and distribute verbatim copies of the Program's source code as you receive …
  19. Delny 0.4.1

    A little while ago I released a new version of Delny (my python wrapper around Qhull for Delaunay triangulations), the main purpose to use numpy instead of numeric. Impressively enough people actually seemed to care and I got a few bug reports and hints for improvements.

    So I just released …

  20. Cross platform shell scripts

    At work we have an rather elaborate collection of shell scripts that builds our softweare and all it's dependencies on about 7 UNIX variants as well as on Windows. Shell seemed like a good choice when we started to write those scripts: it is available on all hosts (using Cygwin …

  21. Battery life

    Normally I'm quite happy with the 3h of battery life of my laptop, it covers all my disconnected time on trains etc. But it just doesn't cut it on a 10h flight, especially painful if my brain has loads of ideas to try out and things to do.

  22. New Delny release

    A few days ago I got another of those two-a-year inquiries about Delny, the python wrapper around Qhull for Delaunay triangulations. But increadably indirectly it finally got me to do a new release, it's only been a few years since the last one! Nothing has changed really, the only difference …

  23. Resuming an scp file transfer

    Sometimes you have to transfer data over dodgy links. And when you're transferring a large file this can hurt when it fails. So as explained elsewhere rsync can safe the day:

    $ scp host:remote_file local_file
    # now interrupt and resume with
    $ rsync --partial --progress --rsh=ssh host:remote_file local_file

    You need …

  24. Should bare except statements be allowed in the Python stdlib?

    Firstly to clarify the terminology, this is bare except statement:


    And this is a non-bare except statement, but bear in mind the type of the exception that is caught can be anything:

    except Exception:

    The point is that both fragments are a catch-all exception handler, only the …

« Page 2 / 7 »