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


Groups > comp.lang.python > #26772

Re: Is there a clever way to pass arguments

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bruceg113355@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'argument': 0.04; 'arguments': 0.07; 'list?': 0.07; 'python': 0.09; 'arguments,': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'index': 0.13; 'definition.': 0.16; 'sequential': 0.16; 'subject:pass': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'thanks,': 0.18; 'wednesday,': 0.22; 'bruce': 0.23; 'statement': 0.23; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'separate': 0.27; 'cc:2**2': 0.27; 'clever': 0.29; 'parameters.': 0.29; 'function': 0.30; 'print': 0.32; 'like:': 0.33; 'turns': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'thank': 0.36; 'does': 0.37; 'listing': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'your': 0.60; 'from:no real name:2**0': 0.60; 'email addr:gmail.com': 0.63; 'subject:there': 0.65; 'august': 0.66; 'works!': 0.84; 'cc:no real name:2**2': 0.91; 'received:209.85.220.184': 0.91; 'angel': 0.93
Newsgroups comp.lang.python
Date Wed, 8 Aug 2012 18:20:40 -0700 (PDT)
In-Reply-To <mailman.3088.1344474457.4697.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=71.162.161.91; posting-account=cxDMTgoAAAD0NMd7UaWriutT-PIoI910
References <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> <mailman.3088.1344474457.4697.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 71.162.161.91
MIME-Version 1.0
Subject Re: Is there a clever way to pass arguments
From bruceg113355@gmail.com
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org, d@davea.name, bruceg113355@gmail.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.3089.1344475242.4697.python-list@python.org> (permalink)
Lines 77
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1344475242 news.xs4all.nl 6933 [2001:888:2000:d::a6]:34788
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26772

Show key headers only | View raw


On Wednesday, August 8, 2012 9:07:04 PM UTC-4, Dave Angel wrote:
> On 08/08/2012 08:41 PM, bruceg113355@gmail.com wrote:
> 
> > Is there a way in Python to pass arguments without listing each argument?
> 
> > For example, my program does the following:
> 
> >
> 
> >     testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7])
> 
> >
> 
> > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list?
> 
> > I cannot change the function definition.
> 
> >
> 
> > Thanks,
> 
> > Bruce
> 
> If a function is expecting exactly 8 arguments, and z is a list of
> 
> length 8, you can call the function like:
> 
> 
> 
>      testData(*z)
> 
> 
> 
> if z is longer, then you'd need something like (untested)
> 
>     testData(*z[:8])
> 
> 
> 
> The * basically turns a list into separate arguments, and these are then
> 
> applied to the formal parameters.
> 
> 
> 
> -- 
> 
> 
> 
> DaveA








Dave, your solution works!

def testData (z0, z1, z2, z3, z4, z5, z6, z7):
    print (z0, z1, z2, z3, z4, z5, z6, z7)
    
z = []
z.append(0)
z.append(1)
z.append(2)
z.append(3)
z.append(4)
z.append(5)
z.append(6)
z.append(7)

testData(*z[:8])

Thank you,
Bruce

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is there a clever way to pass arguments bruceg113355@gmail.com - 2012-08-08 17:41 -0700
  Re: Is there a clever way to pass arguments Andrew Cooper <amc96@cam.ac.uk> - 2012-08-09 01:47 +0100
  Re: Is there a clever way to pass arguments Dave Angel <d@davea.name> - 2012-08-08 21:07 -0400
    Re: Is there a clever way to pass arguments bruceg113355@gmail.com - 2012-08-08 18:20 -0700
    Re: Is there a clever way to pass arguments bruceg113355@gmail.com - 2012-08-08 18:20 -0700
      Re: Is there a clever way to pass arguments Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-09 01:34 +0000
  Re: Is there a clever way to pass arguments Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-08-09 11:05 +0200
  Re: Is there a clever way to pass arguments Chris Angelico <rosuav@gmail.com> - 2012-08-09 19:13 +1000
    Re: Is there a clever way to pass arguments Alister <alister.ware@ntlworld.com> - 2012-08-09 17:14 +0000
      Re: Is there a clever way to pass arguments GangGreene <GangGreene@invalid.com> - 2012-08-09 15:39 -0400
  Re: Is there a clever way to pass arguments Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-08-09 11:50 +0200
  Re: Is there a clever way to pass arguments Terry Reedy <tjreedy@udel.edu> - 2012-08-09 15:48 -0400

csiph-web