Re: Unpaking Tuple

2012-11-18 Thread Hans Mulder
On 9/10/12 08:07:32, Bob Martin wrote: > in 682592 20121008 232126 "Prasad, Ramit" wrote: >> Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = >> 03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= >> tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if le

Re: Unpaking Tuple

2012-11-18 Thread Robert Miles
On 10/9/2012 1:07 AM, Bob Martin wrote: in 682592 20121008 232126 "Prasad, Ramit" wrote: Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = 03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tu

RE: RE: Unpaking Tuple

2012-10-09 Thread Prasad, Ramit
Bob Martin wrote > in 682592 20121008 232126 "Prasad, Ramit" wrote: > >Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = > >03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= > >tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tuple) =3D=3D 4 e

Re: Unpaking Tuple

2012-10-09 Thread Grant Edwards
On 2012-10-09, Bob Martin wrote: > in 682592 20121008 232126 "Prasad, Ramit" wrote: >>Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = >>03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= >>tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tup

Re: mangled messages (was: Unpaking Tuple)

2012-10-09 Thread Jussi Piitulainen
Tim Chase writes: > On 10/09/12 02:22, Jussi Piitulainen wrote: > >>> in 682592 20121008 232126 "Prasad, Ramit" wrote: > > [snip mess] > >>> How does one unpack this post? ;-) > >> > >> Since that's not the way it arrived here, i have to ask, how do you > >> get these posts? > > > > I see a carri

Re: mangled messages (was: Unpaking Tuple)

2012-10-09 Thread Tim Chase
On 10/09/12 02:22, Jussi Piitulainen wrote: >>> in 682592 20121008 232126 "Prasad, Ramit" wrote: > [snip mess] >>> How does one unpack this post? ;-) >> >> Since that's not the way it arrived here, i have to ask, how do you >> get these posts? > > I see a carriage return rendered as ^M at the end

Re: Unpaking Tuple

2012-10-09 Thread Jussi Piitulainen
Dave Angel writes: > On 10/09/2012 02:07 AM, Bob Martin wrote: > > in 682592 20121008 232126 "Prasad, Ramit" wrote: [snip mess] > > How does one unpack this post? ;-) > > Since that's not the way it arrived here, i have to ask, how do you > get these posts? Are you subscribed to individual mess

Re: Unpaking Tuple

2012-10-08 Thread Dave Angel
On 10/09/2012 02:07 AM, Bob Martin wrote: > in 682592 20121008 232126 "Prasad, Ramit" wrote: >> Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = >> 03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= >> tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if

Re: RE: Unpaking Tuple

2012-10-08 Thread Bob Martin
in 682592 20121008 232126 "Prasad, Ramit" wrote: >Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = >03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= >tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tuple) =3D=3D 4 else (my_= >tuple + (None,

RE: Unpaking Tuple

2012-10-08 Thread Prasad, Ramit
Thomas Bach wrote: > Hi there, > > On Sat, Oct 06, 2012 at 03:08:38PM +, Steven D'Aprano wrote: > > > > my_tuple = my_tuple[:4] > > a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] > > > > Are you sure this works as you expect? I just stumbled over the following: > >

Re: Unpaking Tuple

2012-10-08 Thread Joshua Landau
On 8 October 2012 22:45, Thomas Bach wrote: > Hi there, > > On Sat, Oct 06, 2012 at 03:08:38PM +, Steven D'Aprano wrote: > > > > my_tuple = my_tuple[:4] > > a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] > > > > Are you sure this works as you expect? I just stumbled

Re: Unpaking Tuple

2012-10-08 Thread Thomas Bach
Hi there, On Sat, Oct 06, 2012 at 03:08:38PM +, Steven D'Aprano wrote: > > my_tuple = my_tuple[:4] > a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] > Are you sure this works as you expect? I just stumbled over the following: $ python Python 3.2.3 (default, Jun 25

Re: Unpaking Tuple

2012-10-07 Thread Terry Reedy
On 10/7/2012 1:58 PM, woooee wrote: On Oct 6, 3:09 am, sajuptpm wrote: 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) You cannot 'make' buggy code work -- except by changing it. >>> a, b, c, *d = (1,2,3) >>> d [] Why is it

Re: Unpaking Tuple

2012-10-07 Thread woooee
On Oct 6, 3:09 am, sajuptpm wrote: > 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). Why is it necessary to unpack the tuple into arbitrary variables. a_tuple=(1,2,3) for v in a_tuple: print v for ctr in range(le

Re: Unpaking Tuple

2012-10-06 Thread Roy Smith
In article , Chris Rebert wrote: > 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] I usual

Re: Unpaking Tuple

2012-10-06 Thread Chris Rebert
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

Unpaking Tuple

2012-10-06 Thread sajuptpm
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. I know in python 3, you can do `a, b, c, *d = (1, 2, 3)` and then d will contain an