Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90166 > unrolled thread
| Started by | "Frank Millman" <frank@chagford.com> |
|---|---|
| First post | 2015-05-08 15:10 +0200 |
| Last post | 2015-05-08 15:10 +0200 |
| 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? "Frank Millman" <frank@chagford.com> - 2015-05-08 15:10 +0200
| From | "Frank Millman" <frank@chagford.com> |
|---|---|
| Date | 2015-05-08 15:10 +0200 |
| Subject | Re: Is this unpythonic? |
| Message-ID | <mailman.248.1431090654.12865.python-list@python.org> |
"Ben Finney" <ben+python@benfinney.id.au> wrote in message news:85y4kzb90f.fsf@benfinney.id.au... > "Frank Millman" <frank@chagford.com> writes: > >> If I use a list as an argument, I only use it to pass values *into* >> the function, but I never modify the list. > > You've had good reasons why a mutable default argument is a good idea. > > I'll address another aspect of the question: passing a structured > collection of values via a single parameter. > > If those values *always* go together, it sounds like you have a class > which should be defined to make it explicit that they go together. > [...] > > Too much overhead? If you want to collect a meaningful collection of > values together in the same way each time, but don't need any special > behaviour, then a class might be overkill. > > Python has the 'namedtuple' type:: > [...] > > <URL:https://docs.python.org/3/library/collections.html#collections.namedtuple> > documents the surprisingly useful 'namedtuple' factory. > Useful thoughts - thanks, Ben. Here is a typical use case. I have a function which constructs a sql SELECT statement from various input parameters. One of the parameters is used to build up an ORDER BY clause. If ordering is required, the caller passes a list of tuples, each tuple consisting of a column name and a boolean indicating ascending/descending. If no ordering is required, it is convenient for the caller to omit the argument altogether, but then the callee needs a default argument. Previously I had 'order=[]' as a keyword argument, but that gave rise to my query. I have now changed it to 'order=None'. Frank
Back to top | Article view | comp.lang.python
csiph-web