Tech and travel

Category: Python

Using signal.alarm() for a timeout

2014-01-16

The Python signal module let’s you setup Unix signals, including SIGALRM.

Reliable file updates in Python

2013-07-16

Machines can fail, so it’s important to make sure your files are saved. This article has some great ways of doing reliable file updates with python. Great stuff.

Stubbing out open() in Python

2012-05-15

Here’s an example that stubs out the open() function in Python using the mock library.

Cool Python

2011-10-09

Check out the example in the 3rd comment : http://code.activestate.com/recipes/413137-call-a-functionmethod-x-times-per-second/ That is cool.

The __enter__ method in the with statement

2010-07-06

The with statement is a great addition to Python. One thing that might not be immediately clear from the documentation is how the __enter__ method has to be implemented. If you want to use the object containing __enter__ then you have to return self there. You should not create a new object and return it.

Copyright (c) 2024 Michel Hollands