[Tutor] Function list that might have a tuple that might have one of its indexs set to 's'

Paul D. Kraus paul.kraus at gmail.com
Sat Jun 10 04:22:11 CEST 2006


I am writing my first python program(at least in a really long time). Its
purpose is to take csv or pipe delimited files and convert them to html
pages. Was going to be excel but its just not worth the headache. Everyone
viewing the reports is doing just that viewing simple tables.

I need to scan through a list that contains headers to my table.
If one of the elements is a tuple and one of the elements of the tuple is
"s" set self.sort to the index of the tuple in the header list and then
replace the element in header with a two field tuple containing everything
that was not 's'.

header = ['my first column',('my second num column','s','r'),(' my third num
column','r') ]

I pass header to a function actually a method but lets pretend its just a
plain old function. Be careful reading the below code may cause random
strokes. I have woken up twice laying on the floor disoriented.... :)

Actual code in my working example used to call function ...

report.set_header(
['','Ext','Name','',('Calls','r','s'),('Ring','r'),('Talk','r'),('Wait','r'),('Max
Talk','r') ] )

    def set_header(self,header):
        list = []
        for cindex in range(len(header)):
            if type(()) == type(header[cindex]):
                for index in range(len(header[cindex]) ):
                    if header[cindex][index] == 's':
                        self.sort = cindex
                        for tindex in range(len(header[cindex])):
                            if tindex != index: list.append
(header[cindex][tindex])
                        header[cindex] = tuple(list)
        self.header = header

TIA,
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060609/e8af7256/attachment.html 


More information about the Tutor mailing list