newbie question on def, passing param's help

L

Lance Hoffmeyer

Hey all,

I have a def that I have been using but I realized that sometimes I need a LIST with
5 or 6 brands instead of 4 so I want to put LIST outside of the def but I can't wrap
my head around a way to get LIST outside the def while still passing the same 4
parameters in the function. I'm sure there is probably a simple answer but I can't
seem to think of it.

Thanks in advance,

Lance


def attributesbyID(row,base,slideID,spreadsheet):
sh = wb.Worksheets (spreadsheet)
sh.Select()
############### EXCEL SECTION TO GET NUMBERS #############
LIST=((row,base,lastcol,"A13","013"),(row,base,lastcol-1,"A14","014"),(row,base,lastcol-2,"A15","015"),(row,base,lastcol-3,"A16","016"), #brand1
(row+20,base+20,lastcol,"A9","09"),(row+20,base+20,lastcol-1,"A10","010"),(row+20,base+20,lastcol-2,"A11","011"),(row+20,base+20,lastcol-3,"A12","012"),#brand2
(row+40,base+40,lastcol,"A5","05"),(row+40,base+40,lastcol-1,"A6","06" ), (row+40,base+40,lastcol-2,"A7","07" ), (row+40,base+40,lastcol-3,"A8","08" ), #brand3
(row+60,base+60,lastcol,"A1","01"),(row+60,base+60,lastcol-1,"A2","02" ), (row+60,base+60,lastcol-2,"A3","03" ), (row+60,base+60,lastcol-3,"A4","04" )) #brand4
##########################################################
################ POWERPOINT SECTION ######################
for shape in WB.Slides.FindBySlideID(slideID).Shapes:
if (shape.Type== 7):
for oROW,oBASE,oCOL,oCELL,oHEADERCELL in LIST:
oVALUE = sh.Cells(oROW,oCOL).Value
oHEADER = sh.Cells(4,oCOL).Value + " (n=" + str(int(sh.Cells(oBASE,oCOL).Value)) + ")"
PWB = WB.Slides.FindBySlideID(slideID).Shapes(shape.Name)
oGraph = PWB.OLEFormat.Object
oGraph.Application.datasheet.Range(oCELL).Value = oVALUE
oGraph.Application.datasheet.Range(oHEADERCELL).Value = oHEADER

###########################################################
del oGraph
attributesbyID(14,12,31,"Attributes") # attr1





Here is what I want:


LIST=((row,base,lastcol,"A13","013"),(row,base,lastcol-1,"A14","014"),(row,base,lastcol-2,"A15","015"),(row,base,lastcol-3,"A16","016"), #brand1
(row+20,base+20,lastcol,"A9","09"),(row+20,base+20,lastcol-1,"A10","010"),(row+20,base+20,lastcol-2,"A11","011"),(row+20,base+20,lastcol-3,"A12","012"),#brand2
(row+40,base+40,lastcol,"A5","05"),(row+40,base+40,lastcol-1,"A6","06" ), (row+40,base+40,lastcol-2,"A7","07" ), (row+40,base+40,lastcol-3,"A8","08" ), #brand3
(row+60,base+60,lastcol,"A1","01"),(row+60,base+60,lastcol-1,"A2","02" ), (row+60,base+60,lastcol-2,"A3","03" ), (row+60,base+60,lastcol-3,"A4","04" ), #brand4
(row+80,base+80,lastcol,"A1","01"),(row+80,base+80,lastcol-1,"A2","02" ), (row+80,base+80,lastcol-2,"A3","03" ), (row+80,base+80,lastcol-3,"A4","04" )) #brand5


def attributesbyID(row,base,slideID,spreadsheet):
sh = wb.Worksheets (spreadsheet)
sh.Select()
##########################################################
################ POWERPOINT SECTION ######################
for shape in WB.Slides.FindBySlideID(slideID).Shapes:
if (shape.Type== 7):
for oROW,oBASE,oCOL,oCELL,oHEADERCELL in LIST:
oVALUE = sh.Cells(oROW,oCOL).Value
oHEADER = sh.Cells(4,oCOL).Value + " (n=" + str(int(sh.Cells(oBASE,oCOL).Value)) + ")"
PWB = WB.Slides.FindBySlideID(slideID).Shapes(shape.Name)
oGraph = PWB.OLEFormat.Object
oGraph.Application.datasheet.Range(oCELL).Value = oVALUE
oGraph.Application.datasheet.Range(oHEADERCELL).Value = oHEADER

###########################################################
del oGraph
attributesbyID(14,12,31,"Attributes") # attr1
 
L

Lee Harr

I have a def that I have been using but I realized that sometimes I need a LIST with
5 or 6 brands instead of 4 so I want to put LIST outside of the def but I can't wrap
my head around a way to get LIST outside the def while still passing the same 4
parameters in the function. I'm sure there is probably a simple answer but I can't
seem to think of it.

Here is what I want:


LIST=((row,base,lastcol,"A13","013"),(row,base,lastcol-1,"A14","014"),(row,base,lastcol-2,"A15","015"),(row,base,lastcol-3,"A16","016"), #brand1
(row+20,base+20,lastcol,"A9","09"),(row+20,base+20,lastcol-1,"A10","010"),(row+20,base+20,lastcol-2,"A11","011"),(row+20,base+20,lastcol-3,"A12","012"),#brand2
(row+40,base+40,lastcol,"A5","05"),(row+40,base+40,lastcol-1,"A6","06" ), (row+40,base+40,lastcol-2,"A7","07" ), (row+40,base+40,lastcol-3,"A8","08" ), #brand3
(row+60,base+60,lastcol,"A1","01"),(row+60,base+60,lastcol-1,"A2","02" ), (row+60,base+60,lastcol-2,"A3","03" ), (row+60,base+60,lastcol-3,"A4","04" ), #brand4
(row+80,base+80,lastcol,"A1","01"),(row+80,base+80,lastcol-1,"A2","02" ), (row+80,base+80,lastcol-2,"A3","03" ), (row+80,base+80,lastcol-3,"A4","04" )) #brand5


How about if you make this a separate function, and
return the list (actually, what you have here is a
tuple) that you want:

def excells(row, base, lastcol):
thelist = ((row, base, lastcol, "A13", "013"), ...
return thelist


The function might even take other parameters that tell whether
to return 4, 5, or 6 brands.

def attributesbyID(row,base,slideID,spreadsheet):
sh = wb.Worksheets (spreadsheet)
sh.Select()
##########################################################
################ POWERPOINT SECTION ######################

lastcol = ??????
LIST = excells(row, base, lastcol)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top