Tech and travel

Category: Python

Using signal.alarm() for a timeout


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

Reliable file updates in Python


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


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

Cool Python


Check out the example in the 3rd comment : That is cool.

The __enter__ method in the with statement


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