puzzling.org · mary.gardiner.id.au · Macquarie University

Suppressing Python 2.6 DeprecationWarning

Since Python 3.0+ is backwards incompatible (or, if you like, a new Python-esque language), Python 2.6 is enormously grouchy about announcing that everything under the sun has been deprecated. For example:

$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import md5
__main__:1: DeprecationWarning: the md5 module is deprecated; use hashlib instead
>>> 

While this is very helpful for one's own code, my email is now filling with warnings about how Twisted, Venus and several other libraries have deprecated elements (import md5 being a particularly common offender). There's nothing I can do about that, and being warned hourly about some of them is therefore unhelpful. Here's how you turn it off: call python with -Wignore::DeprecationWarning.

$ python -Wignore::DeprecationWarning
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import md5
>>> 

As you can probably guess, by doing this you run the risk of your code failing to work with some future version of Python and you not getting much warning about it. But your inbox or error logs may thank you.

Last modified: 03 May 2009