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


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

Re: Question on keyword arguments

Started byTim Chase <python.list@tim.thechases.com>
First post2016-02-18 08:58 -0600
Last post2016-02-18 08:58 -0600
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 Tim Chase <python.list@tim.thechases.com> - 2016-02-18 08:58 -0600

#103119 — Re: Question on keyword arguments

FromTim Chase <python.list@tim.thechases.com>
Date2016-02-18 08:58 -0600
SubjectRe: Question on keyword arguments
Message-ID<mailman.4.1455808800.2289.python-list@python.org>
On 2016-02-18 09:00, grsmith@atlanticbb.net wrote:
> Would this be the correct way to return
> a list as a default result.
> 
> Also, would the list be the preferable result (to a python
> programmer) ?
> 
> def test(command, return_type='LIST'):
>     """ Go to database and return data"""
>     if return_type == 'LIST':
>         result = ['ONE', 'TWO', 'THREE']
>     else:
>         result = r'0xfeONE\0exfeTWO\0xfeTHREE'

[I presume the "\0exfe" should just be "\0xfe" like the other two]

>     return result
> 
> if __name__ == '__main__':
>     print(test('cmd'))
>     print(test('cmd', 'LIST'))
>     print(test('cmd', None))
>     print(test('cmd', 'string'))

The function should return "the most obvious way to do it".  In this
case, it appears that you should just always return a list.  If you
want to format it in your crazy-other-result format, create a utility
function to do that:

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

  def grsmithify(lst):
    return ''.join("\0xfe%s" % s for s in lst)

  print(test('cmd'))
  print(grsmithify(test('cmd')))

-tkc


[toc] | [standalone]


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


csiph-web