This particular quirk of Python has been discussed in various places before, but I think it bears repeating as it’s different to the behaviour that you might intuitively expect and consequently catches a lot of people out when writing class methods. When declaring a function or a class method, any default arguments are only evaluated at the point when the function is declared, not when the function is called. For mutable default arguments such as lists or dictionaries, this has the effect of making them static. Consider the following example:
We offer the articles below in the hope that they will be useful, but we cannot accept liability for any problems caused by the instructions that they contain. If you have a problem, question or feedback relating to one of our articles, please post a comment so that other readers can benefit. We regularly review comments and reply or update the articles, to ensure their continued usefulness. All articles are provided free, without any advertising or tracking, for the benefit of the technical community.
If you require paid commercial support, please contact us for assistance.
I just spent a couple of hours debugging something really counterintuitive, where PHP’s
print_r seemingly told me that an array had different content to the content that the same array contained according to a
foreach loop. Consider this slightly contrived example code:
In this post I describe how to link together IMAP email, ownCloud calendar and contacts, Roundcube contacts, and set up access to all of them via any mobile device that supports ActiveSync. They don’t all need to be on the same server, but you will need to use the same username and password for IMAP and ownCloud.
In this post, I describe how to override the default rsyncd settings on a Synology diskstation to enable custom daemon mode modules/shares that don’t require user authentication.
In this post, I describe how to troubleshoot and fix an issue with some shared webhosting plans, which causes PHP to return a 403 Forbidden or 404 Not Found error for files that are actually present and readable by all users.
In this article I describe how to configure Z-Push to use a Roundcube contacts database to allow synchronisation of contacts on a smartphone or tablet using ActiveSync.
My past self would be sad and amazed if he could see me how lazy I’ve become. I have a printer plugged into my laptop which runs on Xubuntu but I wanted to be able to print from my iPad while I’m on the sofa downstairs.
I’ve had an HTC Desire 601 for a few months now and have generally been very happy with it. Generally the battery has lasted about 30 hours with minimal use, but last week HTC released a software update which meant battery the battery life went to about 6 hours without me even using it!
In this post, I detail how to setup Nagios to monitor a Windows machine via NSClient++
- A working Nagios install, configured on a server with a fixed IP
- The latest NSClient++ MSI Installer
NOTE: At time of writing, the latest version of NSClient++ is 0.42 and is recommended as 0.41 has issues with binding to IPv4 addresses