pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by frymaster on Tue 31st Dec 12:55
download | new post

  1. #!/usr/bin/python
  2.  
  3. import collections
  4.  
  5. TableEntry = collections.namedtuple("TableEntry","Item_ID Item_Name Maximum_Buy Minimum_Sell Flippable Profit")
  6.  
  7. tbl1 = [TableEntry(1234,"Mobile Phone",56,50,"No",3),TableEntry(1235,"iPad",100,90,"Yes",5)]
  8. tbl2 = [TableEntry(5678,"Laptop",200,180,"No",-20),TableEntry(5679,"Desktop",1000,1200,"Yes",180)]
  9.  
  10.  
  11. section1 = { "Handheld": tbl1, "Computers": tbl2 }
  12.  
  13. wholeDamnThing = {"Electronics" : section1}
  14.  
  15. def outputTable(name,table):
  16.  
  17.     width = len(table[0])
  18.     output = ['<table><tr><th colspan=',str(width),'>',name,'</th></tr>\n']
  19.     output.append('<tr>')
  20.     for field in table[0]._fields:
  21.         output.append('<th>' + field.replace('_',' ') + '</th>')
  22.     output.append('</tr>\n')
  23.     for row in table:
  24.         output.append('<tr>')
  25.         for element in row:
  26.             output.append('<td>' + str(element) + '</td>')
  27.         output.append('<tr>\n')
  28.     output.append('</table>\n')
  29.     return "".join(output)
  30.  
  31. def outputSection(name,section):
  32.     output = ['<div class="section"><h1 class="sectionHeading">' , name , '</h1>\n']
  33.     for table in section:
  34.         output.append(outputTable(table,section[table]))
  35.     output.append('</div>\n')
  36.     return "".join(output)
  37.  
  38. def outputAll(damnThing):
  39.     output = ['Header\n']
  40.  
  41.     for section in damnThing:
  42.         output.append(outputSection(section,damnThing[section]))
  43.     output.append("Footer\n")
  44.     return "".join(output)
  45.  
  46.  
  47.  
  48. print outputAll(wholeDamnThing),

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings