Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98524
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Using tuple as parameter to a function |
| Date | Tue, 10 Nov 2015 00:58:04 +1100 |
| Lines | 36 |
| Message-ID | <mailman.175.1447077487.16136.python-list@python.org> (permalink) |
| References | <87io5b5m1b.fsf@Equus.decebal.nl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de gnRjK0LkJcAr3ZqwtP4bLgJul3KXJYO+j9ZSqGFibAzQ== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'option,': 0.07; 'cc:addr:python-list': 0.09; 'size)': 0.09; 'size;': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'unpack': 0.09; 'question.': 0.13; 'appropriate': 0.14; "(i'm": 0.16; '100))': 0.16; 'count,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guessing': 0.16; 'inclined': 0.16; 'iteration': 0.16; 'parameter,': 0.16; 'possible?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'values:': 0.16; 'wrote:': 0.16; 'instance,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'parameter': 0.22; 'am,': 0.23; "python's": 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'sense': 0.26; 'parameters': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'values': 0.28; 'looks': 0.29; 'work.': 0.30; "i'd": 0.31; 'option': 0.31; 'third': 0.33; 'tue,': 0.34; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'nov': 0.35; 'options:': 0.35; 'something': 0.35; 'but': 0.36; 'possible.': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'doing': 0.38; 'received:209': 0.38; 'names': 0.38; 'some': 0.40; 'easy': 0.60; 'your': 0.60; 'more': 0.63; 'here': 0.66; 'direct': 0.68; 'best-kept': 0.84; 'cecil': 0.84; 'chrisa': 0.84; 'easy!': 0.84; 'subject:Using': 0.84; 'westerhof': 0.84; 'to:none': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=lvsAhwGrahwQS+nMgdSQBXZi0XiZs4BspOz3MIVCjBE=; b=cUEuMRt8ABNAc7EhrUfA2nbAtdijlA1DXgKngQKrtPv2UzuMt15q3wKZoFOjpnBbPI wOQHqPb1vVsk3tzRzvWj+okP4tPayYceInkK1bsM4fNzPq0OMGd2kpimgbZ9jyZ/ZCHj Z7WOQYLU5nVNkl1GnhDbVPgh9jHWZdroHbCtYVUoTK0zNKck7QziBLJSOHxV96VQIFk6 kpLzuE8NfLGMIs0tscyLcgZY1m5ASYpHLH+md9tSFAd8/vfYkOB1SMpO9Tn3tWRQQIG7 cjL0YPdr21GYRiIrqc6f27dX524mcXlhIanUlFZuEdHhpT95g0pujv+ynjtK6zhT6wxr afNg== |
| X-Received | by 10.107.16.84 with SMTP id y81mr16804998ioi.19.1447077484213; Mon, 09 Nov 2015 05:58:04 -0800 (PST) |
| In-Reply-To | <87io5b5m1b.fsf@Equus.decebal.nl> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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:98524 |
Show key headers only | View raw
On Tue, Nov 10, 2015 at 12:40 AM, Cecil Westerhof <Cecil@decebal.nl> wrote:
> I was thinking about something like:
> values = (( 1, 100), ( 2, 100), ( 5, 100),
> 10, 100), (20, 100), (40, 100))
> for value in values:
> do_stress_test('sqlite', ???)
> do_stress_test('postgres', ???)
>
> Is this possible? If so: what do I put at the place of the '???'?
>
> I could change the second and third parameter to a tuple as the second
> parameter, but I prefer three parameters if that would be possible.
Easy! Just unpack the tuple. Two options:
# Unpack in the loop
for count, size in values:
do_stress_test('sqlite', count, size)
do_stress_test('postgres', count, size)
# Unpack in the function call
for value in values:
do_stress_test('sqlite', *value)
do_stress_test('postgres', *value)
Either will work. For what you're doing here, I'd be inclined to the
first option, so you can give the values appropriate names (I'm
completely guessing here that they might be some sort of iteration
count and pool size; use names that make sense to your program); the
other option looks uglier in this particular instance, though it's a
more direct answer to your question.
This is one of Python's best-kept secrets, I think. It's not easy to
stumble on it, but it's so handy once you know about it.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using tuple as parameter to a function Cecil Westerhof <Cecil@decebal.nl> - 2015-11-09 14:40 +0100
Re: Using tuple as parameter to a function Chris Angelico <rosuav@gmail.com> - 2015-11-10 00:58 +1100
Re: Using tuple as parameter to a function marco.nawijn@colosso.nl - 2015-11-09 06:57 -0800
Re: Using tuple as parameter to a function Cecil Westerhof <Cecil@decebal.nl> - 2015-11-09 16:01 +0100
Re: Using tuple as parameter to a function Chris Angelico <rosuav@gmail.com> - 2015-11-10 02:24 +1100
Re: Using tuple as parameter to a function Cecil Westerhof <Cecil@decebal.nl> - 2015-11-09 18:54 +0100
csiph-web