Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103116
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Question on keyword arguments |
| Date | 2016-02-18 15:37 +0100 |
| Organization | None |
| Message-ID | <mailman.3.1455806258.2289.python-list@python.org> (permalink) |
| References | <62136715E19142B6B318EA3A3DF04D40@OPTIPLEX990> |
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
Re: Question on keyword arguments Peter Otten <__peter__@web.de> - 2016-02-18 15:37 +0100
csiph-web