[Zope] Return a image instance from script

Tino Wildenhain tino at wildenhain.de
Mon Dec 22 15:41:07 EST 2003


Hi Christoph,

Christoph Landwehr wrote:
> A very simple (?) problem:
> 
> from a script I want to pass an image object to an external method.
> 
> In Python:
>  >>> def test():
> ...   foo=open('new.gif')
> ...   return foo
> ...
>  >>> test()
> <open file 'new.gif', mode 'r' at 0x80df2e0>

Thats not an Image object, its just a file object
or rather its repr()

> 
> 
> In Zope:
> def test():
>   foo=open('new.gif')
>   return foo

I really doubt the open() part here.

> 
> This does not return an instance of the image but
> <img src="http://foo.bar.com" alt="" title="" height="10" width="10" 
> border="0" />
> 
> Zope's doing some magic. How do I get the image object?

No, it just uses repr() here, which maps to the objects __str__
Method which happens to render a HTML tag for the image.

if foo is an instance of zopes Image, foo has attributes
like width, hight and so on - in short, its your image.

It depends on what you want to do with it.

Everything you need to know about these objects is in the
Zopebooks API reference.

Regards
Tino




More information about the Zope mailing list