Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'argument': 0.05; 'column': 0.07; 'explicit': 0.07; 'indicating': 0.07; 'modify': 0.07; 'caller': 0.09; 'function,': 0.09; 'meaningful': 0.09; 'omit': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'required,': 0.09; 'python': 0.11; 'wrote': 0.14; '*always*': 0.16; 'argument,': 0.16; 'argument.': 0.16; 'boolean': 0.16; 'callee': 0.16; 'clause.': 0.16; 'constructs': 0.16; 'mutable': 0.16; 'parameter.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'tuple': 0.16; 'tuples,': 0.16; 'thanks,': 0.17; 'passing': 0.19; 'thoughts': 0.19; 'input': 0.22; 'select': 0.22; 'previously': 0.22; 'aspect': 0.24; 'case.': 0.24; 'convenient': 0.24; 'passes': 0.24; 'typical': 0.24; 'together.': 0.24; 'pass': 0.26; 'defined': 0.27; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'statement': 0.30; "skip:' 10": 0.31; 'consisting': 0.31; 'parameters.': 0.31; 'question:': 0.31; 'writes:': 0.31; 'class': 0.32; 'another': 0.32; 'url:python': 0.33; 'but': 0.35; 'keyword': 0.36; 'useful': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.37; 'list': 0.37; 'list.': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'url:3': 0.61; "you've": 0.63; 'address': 0.63; 'name': 0.63; 'here': 0.66; 'frank': 0.68; 'default': 0.69; 'special': 0.74; 'subject:this': 0.83; 'together,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Is this unpythonic? Date: Fri, 8 May 2015 15:10:52 +0200 References: <85y4kzb90f.fsf@benfinney.id.au> X-Gmane-NNTP-Posting-Host: 197.86.223.132 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431090654 news.xs4all.nl 2905 [2001:888:2000:d::a6]:38980 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90166 "Ben Finney" wrote in message news:85y4kzb90f.fsf@benfinney.id.au... > "Frank Millman" 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:: > [...] > > > 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