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


Groups > comp.lang.python > #103116 > unrolled thread

Re: Question on keyword arguments

Started byPeter Otten <__peter__@web.de>
First post2016-02-18 15:37 +0100
Last post2016-02-18 15:37 +0100
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.


Contents

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

#103116 — Re: Question on keyword arguments

FromPeter Otten <__peter__@web.de>
Date2016-02-18 15:37 +0100
SubjectRe: Question on keyword arguments
Message-ID<mailman.3.1455806258.2289.python-list@python.org>
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"))

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web