list to tuple conversion

Gary M. Josack gary at byoteki.com
Wed Oct 1 04:00:11 EDT 2008


sc wrote:
> clp:
>
> Thanx to a recent thread I am able to have a print string
> with a variable number of formatters -- what I now lack for
> the creation of an elegant print statement is a tuple -- 
> following is the code, the last line of which does not work:
>
> <code>
> #!/usr/bin/python
> import xml.sax
> import eaddyhandler
> parser = xml.sax.make_parser()
> h = eaddyhandler.EAddyHandler()
> parser.setContentHandler(h)
> parser.parse(".ea.xml")
> for i in range(1, len(h.m)):
>     k = "r%06d" % i
>     col = len(h.m[k])
>     if col > 2 and h.m[k][0] > " ":
>         print (col * '%-30s') % h.m[k]
> </code>
>
> What's going on is I have an oocalc spreadsheet for 
> e-addresses -- column 1 has the name, and then I keep 
> adding e-addresses for ppl when they get new ones, as 
> successive entries on their row, meaning each row has
> a variable number of e-address columns.  I have an xml
> extractor that runs before this script using 
> odf.opendocument, which works famously.
>
> My class, EAddyHandler, also works, and builds its dictionary 
> of rows in 'm', forgive me, no flames please, I needed a 
> short name for the dictionary I have to type it so many times.
> The key to 'm' is an 'r' + row number, so I can get
> stuff out of it and it's still in the right order, fun
> with dictionaries.
>
> What I was hoping for was something that could vary the
> source for the print statement as cleanly as the 'col'
> multiplication creates the print format, but the list,
> 'h.m[k]' is not a tuple, it's a list, and I'm just not 
> quite where I am trying to get with this.
>
> If there were a builtin function that took a list and 
> returned a tuple, I'd be there, but if there is such a
> thing I need someone to point me at it.  I can't help
> thinking I am missing some obvious construct, and I'll
> be advised to go reread the tutorial, but I'm not there,
> and if you can take pity on me and point me there, I'll
> be your friend for life.  Well -- I'll be grateful...
>
> TIA,
>
> Scott
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>   
 >>> L = [1,2,3,4,5]
 >>> t = tuple(L)
 >>> t
(1, 2, 3, 4, 5)




More information about the Python-list mailing list