[Zope] Newbie - passing a list to an External Method

Ashley Lloyd ashleylloyd@hotmail.com
Tue, 22 Apr 2003 10:01:25 +0100


Dylan,

Thanks very much for the reply.

AFAIK, there is absolutely no change made to lines before trying to use it, 
but I'll put a bit more detail in here, so someone can no doubt prove me 
wrong!

I set the value of lines, passed to the external method, to be:
['Hello, this is my test pdf', 'This is still my test pdf.', 'Still here', 
'and this is the end ..']

(
Just in case, this is done using a python script:
lines=[]
lines.append("Hello, this is my test pdf")
lines.append("This is still my test pdf.")
lines.append("Still here")
lines.append("and this is the end ..")
return lines
)

If the code in the External Method is:

********************************************************************
#!/usr/bin/env python
def run(fileID, 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
   for line in lines:
       sping.stringformat.drawString(canvas, line, 10,y)
       y = y + 20

   canvas.flush()
   canvas.save()
   return fileID
********************************************************************
Then I get the following error details:

====================================================================
Error Type AttributeError
Error Value __getitem__
Traceback (most recent call last):
File "C:\PROGRA~1\ZopeSite\lib\python\DocumentTemplate\DT_Try.py", line 149, 
in render_try_except
result = render_blocks(self.section, md)
File "C:\PROGRA~1\ZopeSite\lib\python\DocumentTemplate\DT_Let.py", line 75, 
in render
else: d[name]=expr(md)
File "C:\PROGRA~1\ZopeSite\lib\python\DocumentTemplate\DT_Util.py", line 
159, in eval
return eval(code, d)
File "", line 2, in f
File 
"C:\PROGRA~1\ZopeSite\lib\python\Products\ExternalMethod\ExternalMethod.py", 
line 198, in __call__
try: return apply(f,args,kw)
File "C:\PROGRA~1\ZopeSite\Extensions\formatted-strings.py", line 21, in run
from sping.PDF import PDFCanvas
AttributeError: __getitem__
====================================================================

Whereas, if the code in the External Method is:

********************************************************************
#!/usr/bin/env python
def run(fileID, 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)
   return lines
********************************************************************

then this returns the value of lines in the manner above.

What am I doing wrong?

TIA,

Ashley




From: Dylan Reinhardt <zope@dylanreinhardt.com>
Reply-To: zope@dylanreinhardt.com
To: Ashley Lloyd <ashleylloyd@hotmail.com>
CC: zope@zope.org
Subject: Re: [Zope] Newbie - passing a list to an External Method
Date: 17 Apr 2003 10:11:17 -0700

On Thu, 2003-04-17 at 08:01, Ashley Lloyd wrote:
 > Error Type: AttributeError
 > Error Value: __getitem__

This error is typical when the object you're trying to iterate over
isn't a sequence.  Most likely, something you've done on lines 2-27 has
changed the value of lines to None.

Look extra carefully at any and all assignments you make in the external
method.  In particular, it's possible you may have committed a common
error with lists, ex:

a = [1,2.3]
b = a
b = None
# now the value of a is None!

HTH,

Dylan




_________________________________________________________________
On the move? Get Hotmail on your mobile phone http://www.msn.co.uk/mobile