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' …
All Articles
-
-
Using lib2to3 in setup.py
It seems that many people think you need distribute if you want to run 2to3 automatically in your setup.py. 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 …
-
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 …
-
Registering callbacks: to quack like a duck or tell which bit will quack the duck way?
When you have someplace where you register a set of callbacks you have a few options:
- Use an interface-style API. I.e. you have a Mixin style class defining the methods expected to be present, probably just raising NotImplementedError. You then just pass in the entire object to the .register …
-
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 …
-
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?
-
Terminology
Why was it ever considered desirable to call a directory containing a __init__.py 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 …
-
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 …
-
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 …
-
Calling COM methods in C
-
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 …
-
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 …
-
setuptools vs distribute
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 …
-
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 …
-
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.
- Be sensible, this one overrules all the others
- Keep left unless overtaking
- KEEP LEFT UNLESS OVERTAKING
- KEEP LEFT UNLESS OVERTAKING …
-
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 …
-
On using .__getstate__()
Do not, I repeat, do not define .__getstate__() idly.
Thank you very much
-
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 >>>
Nice!
-
The new faces of Europe
I can't help but agree.
-
Finding memory leaks in extension modules
After reading Ned Batchelder's post on his experience hunting a memory leak (which turned out to be a reference counting error) it occurred to me that even tough I have a script to check memory usage I should also really be checking reference counts with sys.gettotalrefcount(). And indeed, after …
-
New Python System Information release!
I've just released a new version of PSI! PSI is a cross-platform Python package providing real-time access to processes and other miscellaneous system information such as architecture, boottime and filesystems. Among the highlights of this release are:
- Improved handling of time
- We now have our own object to represent time …
-
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 …
-
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:
- You may copy and distribute verbatim copies of the Program's source code as you receive …
-
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 …
-
No permission to see Ubuntu bugs?
So I'm looking at the release notes for Ubuntu 9.10 and am interested in the hibernation issue. Naturally I follow the link to the bug report.
First I need to log in to launchpad. That's weird, since when do I need to log in simply to view bugs? But …
-
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 …
-
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.
-
New Delny release
-
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 …
-
Should bare except statements be allowed in the Python stdlib?
Firstly to clarify the terminology, this is bare except statement:
try: ... except: ...
And this is a non-bare except statement, but bear in mind the type of the exception that is caught can be anything:
try: ... except Exception: ...
The point is that both fragments are a catch-all exception handler, only the …