Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90125 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2015-05-08 18:25 +1000 |
| Last post | 2015-05-08 18:25 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Is this unpythonic? Chris Angelico <rosuav@gmail.com> - 2015-05-08 18:25 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-05-08 18:25 +1000 |
| Subject | Re: Is this unpythonic? |
| Message-ID | <mailman.225.1431073517.12865.python-list@python.org> |
On Fri, May 8, 2015 at 6:01 PM, Frank Millman <frank@chagford.com> wrote: > I have often read about the gotcha regarding 'mutable default arguments' > that frequently trips people up. > > I use them from time to time, but I have never had a problem. I have just > delved a bit deeper to see if I am skating on thin ice. > > AFAICT my usage is safe. If I use a list as an argument, I only use it to > pass values *into* the function, but I never modify the list. So if I omit > the argument, the original default empty list is used, otherwise the list > that I pass in is used. In that case, you may want to consider using a default of () rather than [], unless there's some reason that it has to be a list. With a tuple, you have a guarantee that it's not going to be changed, so it's as safe as a default argument of True or 42 or "Hello". That may or may not help, but it's worth considering, especially if all you really need is an iterable (or a sequence). ChrisA
Back to top | Article view | comp.lang.python
csiph-web