[Tutor] Is there a better way to write this function?
Paul D. Kraus
paul.kraus at gmail.com
Sat Jun 10 00:58:58 CEST 2006
This is a second... the first one never hit the list. *shrug* should i be
using a different interface to post? is this a gateway to newsgroup?
I am writing my first python program(at least in a really long time). Its
purpose is to take csv or pipe delimintaed 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060609/6e820b5c/attachment.html
More information about the Tutor
mailing list