Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103119
| Path | csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Question on keyword arguments |
| Date | Thu, 18 Feb 2016 08:58:03 -0600 |
| Lines | 42 |
| Message-ID | <mailman.4.1455808800.2289.python-list@python.org> (permalink) |
| References | <62136715E19142B6B318EA3A3DF04D40@OPTIPLEX990> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de jojKeTC9k4osnXEHBXBUUwBnbcZUqDS6u7oKro+MPQhQ== |
| Return-Path | <python.list@tim.thechases.com> |
| 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; 'lst)': 0.09; 'preferable': 0.09; 'python': 0.10; 'def': 0.13; 'result.': 0.15; "'__main__':": 0.16; '-tkc': 0.16; '09:00,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'it".': 0.16; 'presume': 0.16; 'programmer)': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'appears': 0.23; 'header:In-Reply-To:1': 0.24; 'format,': 0.27; 'correct': 0.28; 'function': 0.28; "skip:' 10": 0.28; '"the': 0.32; 'utility': 0.33; 'case,': 0.34; 'list': 0.34; 'skip:p 30': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'list.': 0.37; 'format': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'default': 0.61; 'obvious': 0.76; 'received:23': 0.84 |
| X-Sender-Id | wwwh|x-authuser|tim@thechases.com |
| X-Sender-Id | wwwh|x-authuser|tim@thechases.com |
| X-MC-Relay | Neutral |
| X-MailChannels-SenderId | wwwh|x-authuser|tim@thechases.com |
| X-MailChannels-Auth-Id | wwwh |
| X-MC-Loop-Signature | 1455807649883:1956593205 |
| X-MC-Ingress-Time | 1455807649883 |
| In-Reply-To | <62136715E19142B6B318EA3A3DF04D40@OPTIPLEX990> |
| X-Mailer | Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) |
| X-AuthUser | tim@thechases.com |
| 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:103119 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Question on keyword arguments Tim Chase <python.list@tim.thechases.com> - 2016-02-18 08:58 -0600
csiph-web