Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'python': 0.09; 'received :mail-vb0-f46.google.com': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'valueerror': 0.09; 'cc:addr:python-list': 0.10; 'sat,': 0.15; 'oct': 0.16; 'slicing:': 0.16; 'wrote:': 0.17; 'received:209.85.212.46': 0.18; 'assuming': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'values': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'chris': 0.28; '>>>>': 0.29; 'items"': 0.29; 'case,': 0.29; 'code': 0.31; 'handle': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'list,': 0.39; 'header:Received:5': 0.40; 'note:': 0.64; '"too': 0.84; 'sender:addr:chris': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=YaFoGpj1PnMPh2YomhcgcxU3XlC1prCuG068dBlestI=; b=SIS22SK866SMXDd6OfQwYmDDKey5mjcwQjLVOAjU8dQZSRRVqYdFdi3OuJ3G4/eGZG FaEwIiAE1kLz9xO0ZZwGWE4gqSST0ttUL67JughQx/0MLqZvD42AaT2Q6+hblzvfuLTg EI/GZMbTOkv3aCB0I73CcPQYovkFB26cnaw/c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=YaFoGpj1PnMPh2YomhcgcxU3XlC1prCuG068dBlestI=; b=IG9azsPULu43a8fwBrmG1p+ANaqNGDr2Bu3toijrhHKa6aXDfjSsXxhfOubq2f1ixc LIhoXllSyyQLWBKcKlrt4f7UTNsku+q1MKXvgvML2M8m9HP58YmZZi8b3RwBGePQ7rRV ZjScR8DpRbBIl7cMh6xK2rbi5tB7qlpSzHyzBeVmR1OmEJlZ5zaulmWqyKRufdtt+RK5 rz5lMDUp18yAOW+mlaB9mG70yLSsyAbBxuBcJqMMd7/Ep1Jk2D6xoB+1r98oPHu2x1kP k4zfRXl9y8Z7ELa4YGY0sU+YU9avkhOcEMtozManB1FJFAk6IvDOm4/F25JygTKYx4XZ 9/1A== MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> Date: Sat, 6 Oct 2012 03:27:52 -0700 X-Google-Sender-Auth: HIG_om7rafsLT1THawxxj8Iv4rs Subject: Re: Unpaking Tuple From: Chris Rebert To: sajuptpm Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQmrrKkz10czrhFsNaoezgQDKBtYM6/yGvhHpl7M848Zl+HWEkW1kUBUViQC4hbfE6eT5Yg4 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349519275 news.xs4all.nl 6874 [2001:888:2000:d::a6]:33705 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30883 On Sat, Oct 6, 2012 at 3:09 AM, sajuptpm wrote: > Hi, > > I am using python 2.6. > > I need a way to make following code working without any ValueError . >>>> a, b, c, d = (1,2,3,4) >>>> a, b, c, d = (1,2,3). > > Note: Number of values in the tuple will change dynamically. Then you arguably want a list, not a tuple. But at any rate: shortfall = 4 - len(your_tuple) your_tuple += (None,) * shortfall # assuming None is a suitable default a, b, c, d = your_tuple If you also need to handle the "too many items" case, use slicing: a, b, c, d = your_tuple[:4] Cheers, Chris