Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103116

Re: Question on keyword arguments

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Question on keyword arguments
Date Thu, 18 Feb 2016 15:37:16 +0100
Organization None
Lines 42
Message-ID <mailman.3.1455806258.2289.python-list@python.org> (permalink)
References <62136715E19142B6B318EA3A3DF04D40@OPTIPLEX990>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de /KCFPaf0iFwaQD9G6QzriAXelK10KK593F51L9oxlUGQ==
Return-Path <python-python-list@m.gmane.org>
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; 'else:': 0.03; '"""': 0.05; 'subject:Question': 0.05; '__name__': 0.07; 'preferable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'def': 0.13; 'argument': 0.15; 'result.': 0.15; "'__main__':": 0.16; 'instead:': 0.16; 'programmer)': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'passing': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'separate': 0.27; 'object,': 0.27; 'correct': 0.28; 'usually': 0.33; 'list': 0.34; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'desired': 0.37; 'skip:p 20': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'default': 0.61
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd93fc.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103116

Show key headers only | View raw


grsmith@atlanticbb.net wrote:

> Would this be the correct way to return
> a list as a default result.

If it does what you want it to do it is "correct" as in "complies with 
specification".
 
> Also, would the list be the preferable result (to a python programmer) ?

A list as a return value is OK as is any other object, however,

> def test(command, return_type='LIST'):

passing the desired result type as an argument is usually not a good idea. 

>     """ Go to database and return data"""
>     if return_type == 'LIST':
>         result = ['ONE', 'TWO', 'THREE']
>     else:
>         result = r'0xfeONE\0exfeTWO\0xfeTHREE'
>     return result
> 
> if __name__ == '__main__':
>     print(test('cmd'))
>     print(test('cmd', 'LIST'))
>     print(test('cmd', None))
>     print(test('cmd', 'string'))

Make it separate functions instead:

def test(command):
    return ["ONE", "TWO", "THREE"]

def test_as_string(command, sep=","):
    return sep.join(test(command))

if __name__ == '__main__':
    print(test("cmd"))
    print(test_as_string("cmd"))

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question on keyword arguments Peter Otten <__peter__@web.de> - 2016-02-18 15:37 +0100

csiph-web