Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79151
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-10-15 09:06 -0700 |
| References | <64f7e57a-4be3-44f4-b11c-0d270fc91809@googlegroups.com> <6004f171-689a-4a69-9b3d-2800fc4216d5@googlegroups.com> |
| Message-ID | <07fd3d66-6343-4fe4-bb38-5d98eff4062d@googlegroups.com> (permalink) |
| Subject | Re: Parsing Python dictionary with multiple objects |
| From | Rustom Mody <rustompmody@gmail.com> |
On Wednesday, October 15, 2014 9:22:48 PM UTC+5:30, Anurag Patibandla wrote: > Thanks Rustom for the advice. > I am new to Python and getting struck at some basic things. How do I assign the values that I am printing to 3 variables say dict1, dict2, dict3? > When I try to assign them before the print statement like this: > d1, d2, d3 =[(queues[j], json.get(queues[j])) for j in range(len(queues))] > I get an error saying 'need more than one value to unpack' Probably means your comprehension [(queues[j], json.get(queues[j])) for j in range(len(queues))] is having less than 3 values >>> lst = [1,2,3] >>> x,y,z = lst >>> (x,y,z) # note no need to print (1, 2, 3) >>> lst=[1] >>> x,y,z=lst Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: need more than 1 value to unpack >>> lst=[1,2,3,4] >>> x,y,z=lst Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: too many values to unpack ================ I suggest youdont directly start with multiple assignment Instead do it in two steps dicts = [(queues[j], json.get(queues[j])) for j in range(len(queues))] d0 = dicts[0] d1 = dicts[1] d2 = dicts[2] When that works go to the more compact form Also please get rid of the range(len(queues)) Its unpythonic!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Parsing Python dictionary with multiple objects anuragpatibandla7@gmail.com - 2014-10-14 08:57 -0700
Re:Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-14 13:02 -0400
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 14:15 -0700
Re: Parsing Python dictionary with multiple objects Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-14 16:32 -0500
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 14:36 -0700
Re: Parsing Python dictionary with multiple objects MRAB <python@mrabarnett.plus.com> - 2014-10-14 23:58 +0100
Re:Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-14 21:57 -0400
Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-14 19:32 -0700
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 20:40 -0700
Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-14 21:50 -0700
Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 13:43 -0400
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 11:35 -0700
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 20:41 -0700
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 08:52 -0700
Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 09:06 -0700
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 09:28 -0700
Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 09:43 -0700
Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 09:59 -0700
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 09:57 -0700
Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 13:48 -0400
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 10:00 -0700
Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 10:10 -0700
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 10:20 -0700
Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 13:50 -0400
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 10:20 -0700
Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 10:35 -0700
Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 11:27 -0700
Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 18:25 -0400
csiph-web