Question on keyword arguments
__peter__ at web.de
Thu Feb 18 09:37:16 EST 2016
grsmith at 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
> 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']
> result = r'0xfeONE\0exfeTWO\0xfeTHREE'
> return result
> if __name__ == '__main__':
> print(test('cmd', 'LIST'))
> print(test('cmd', None))
> print(test('cmd', 'string'))
Make it separate functions instead:
return ["ONE", "TWO", "THREE"]
def test_as_string(command, sep=","):
if __name__ == '__main__':
More information about the Python-list