Re: [Zope] Newbie - passing a list to an External Method
Chris, thanks again for your help, although I'm not sure I know exactly what you mean (my stupidity as opposed to anything else!). There is very little to this External Method: def run(self) REQUEST = self.REQUEST fileID = REQUEST.fileId lines = REQUEST.lines import sping.stringformat from sping.PDF import PDFCanvas from sping.PS import PSCanvas filename="c:/zopepdf/"+fileID canvas = PDFCanvas(size=(350,200), name=filename) y = 20 # return lines works fine here for line in lines: # this is the line where the error is reported. # print line here also generates the same __getitem__ AttributeError sping.stringformat.drawString(canvas, line, 10,y) y = y + 20 canvas.flush() canvas.save() # If trying to print line I try returning printed here instead return fileID I don't know what other debugging I can do, so would be grateful for suggestions. Again, if I define, or over-write the lines variable inside the External Method, (ie lines=[], lines.append ...) then it works fine, its just when it retrieves lines from request, or it is passed as a parameter. Cheers Ashley _________________________________________________________________ Hotmail messages direct to your mobile phone http://www.msn.co.uk/mobile
Somehow what lines refers to is changing... that much seems clear. Since lines appears to suvive intact until just before your loop, we can assume that this is not a problem with passing lines *in* so much as it's a problem with preserving the intended value of lines all the way to the end of the code. Longer term, you'll want to read up on debugging in Python. For now, let's just kludge something together. Put this in the same file as your external method code, just above run(): def lines_check(lines): type_info = 'lines is type: %s\n' % type(lines) return type_info + 'lines has value: %s' % lines Now we start seeing what's what. At any point in your code we can get a quick snapshot of what's up with lines with: return lines_check(lines) Insert this expression at various points in your code, probably starting with just after the definition and at the end of your loop. Obviously, you'll only be able to check one line at a time. Assuming they return different things, work inward to find the place where lines changes and determine what it changes to. HTH, Dylan
participants (2)
-
Ashley Lloyd -
Dylan Reinhardt