Should Python raise a warning for mutable default arguments?

Steven D'Aprano steve at
Sat Aug 23 03:54:00 CEST 2008

On Fri, 22 Aug 2008 14:39:11 -0700, Emile van Sebille wrote:

> Dan wrote:
>> I'd suggest that at the
>> end of the tutorial, when people have a better general idea of how
>> Python works, there would be a Python Gotchas section.
> Hmmm, OK -- mutable defaults, integer division, name mangling...
> I'd think decimal precision is more a general problem than a python
> problem, but still one that throws newbies...
> Any other ideas for gotcha's (as opposed to faqs)?

Augmented assignment: x ?= y is not always the same as x = x ? y.

Repeated string addition can be very slow. For that matter, so can list 

Inserting at the beginning of lists is slow.

Everything about unicode is a Gotcha! *wink*

Raw strings are not designed for Windows paths, they're designed for 
regexes. Consequently, you can't write the following:


list.sort() and list.reverse() return None.

sorted() returns a list, but reversed() returns an iterator.

urllib2.urlopen() will automatically detect the proxy in your environment 
and use that. That's usually a feature, but sometimes it can be a gotcha.

urllib2 doesn't work well with some HTTPS proxies. This is, I believe, a 
known bug, but until it is fixed, it can be a gotcha.


More information about the Python-list mailing list