[Tutor] How to get the keys of a dict inside a dict. ValueError: too many values to unpack

Steve Willoughby steve at alchemy.com
Mon Aug 8 15:00:23 CEST 2011


On 08-Aug-11 02:20, Kayode Odeyemi wrote:
>     Either way, once you have the list of the keys you want to display,
>     print them out once as column headings
>
>
> My concern is how do I print them out as columns, since writer.writerows
> is currently lining them out as rows (\n)
> Is there a function available for me to do this or do I have to
> construct the column structure myself, possibly leveraging
> the tab character or just basically construct a while loop and append
> spaces to each keys found?

I would suggest using the string format() method to lay out the columns 
as you want them.  You could use tab, but if your data values vary much, 
you'll get inconsistent results (i.e., if one row's value goes past the 
next tab stop).  You'll want to create your own for loop to iterate over 
the (possibly sorted) list of values, printing each row the way you want it.

>
> Thanks
>
> On Mon, Aug 8, 2011 at 9:41 AM, Steve Willoughby <steve at alchemy.com
> <mailto:steve at alchemy.com>> wrote:
>
>     Either way, once you have the list of the keys you want to display,
>     print them out once as column headings
>
>
>
>
> --
> Odeyemi 'Kayode O.
> http://www.sinati.com. t: @charyorde
>


-- 
Steve Willoughby / steve at alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C


More information about the Tutor mailing list