Re: [Zope] Newbie - passing a list to an External Method
Longer term, you'll want to read up on debugging in Python. Agreed! For now, let's just kludge something together. Thank you, yet again
I put your code into the External Method, and called it just before the loop. If I return lines_check(lines), then it just sends back: lines is type: lines has value: Yet if I replace that - in exactly the same place, with return lines, then it returns the expected value of lines. If I meddle with lines_check, and just let it do: return lines Then it returns the value, but if it just does: return 'lines has value: %s' % lines Then it does not return anything! ??????? Cheers Ashley _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger
On Wed, 2003-04-23 at 08:30, Ashley Lloyd wrote:
If I return lines_check(lines), then it just sends back:
lines is type: lines has value:
Nothing?? Uh.... that's pretty weird.
Yet if I replace that - in exactly the same place, with return lines, then it returns the expected value of lines.
Even weirder. So let's grasp at the next straw, shall we? Doing a quick grep over sping, it would appear that the stringformat module (which you import) also uses a variable called lines. It *looks* like it defines & used it locally, but I didn't do any real analysis. Let's just work on the assumption that it's more than a coincidence that *your* lines variable gets busted at some point after you make use of a module that *also* has a lines variable. Give this a try: ----------------------- # lines changed to my_lines def run(self) REQUEST = self.REQUEST fileID = REQUEST.fileId my_lines = REQUEST.lines[:] # make a copy, for grins 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 for line in my_lines: sping.stringformat.drawString(canvas, line, 10,y) y += 20 canvas.flush() canvas.save() return fileID ----------------------- Getting warmer? Dylan
Ashley Lloyd wrote:
Longer term, you'll want to read up on debugging in Python.
Agreed!
For now, let's just kludge something together.
Thank you, yet again
I put your code into the External Method, and called it just before the loop. If I return lines_check(lines), then it just sends back:
lines is type: lines has value:
Look at the source of the page where you see that, if your browser tries to interpret the return value as html, this will hide things like <type 'bla'>. Oh, and like Chris, I'm quite sure that "lines" is not what you think it is. If you want to prove or disprove dylan's theory about an imported module poluting the namespace - which I doubt, for one because you said it worked if you manually assign lines in the external method - just rename it to i.e. my_lines, IOW: my_lines = REQUEST.lines and so on. Another thing, I think you are calling your External Method now like. <dtml-call "REQUEST.set(.., lines=mylines). ... hmm, wait Is mylines the name of the python script you mentioned? That would explain everything. Try REQUEST.set(.., lines=mylines()). HTH, oliver
On Wed, 2003-04-23 at 09:50, Oliver Bleutgen wrote:
Look at the source of the page where you see that, if your browser tries to interpret the return value as html, this will hide things like <type 'bla'>.
Ah! Good catch... that would also explain the apparent loss of the newline character.
Is mylines the name of the python script you mentioned?
That would explain everything.
It sure could. If lines turned out to be an instance, it, too, would produce a tag-like thing that would be hidden in Ashley's HTML source. I'm glad someone else picked up this thread... clearly I was running out of ideas. :-) Dylan
participants (3)
-
Ashley Lloyd -
Dylan Reinhardt -
Oliver Bleutgen