[Zope] PHP style variable variables in Python?

Casey Duncan casey@zope.com
Wed, 10 Apr 2002 09:47:03 -0600


If all of the images are in one folder, then the choice function of the 
random module will work. For example:

from random import choice
random_id = choice(context.objectIds('Image'))
return context[random_id]

This assumes that the current context is a folder (or folderish object 
at least). I use objectIds above (instead of objectValues) to prevent 
every image in the folder from being loaded into memory when this is called.

hth,

-Casey

Michael LaPera wrote:
> Hello,
> 
> First of all I am new to Python and Zope coming from Java/PHP.
> 
> I am creating a simple Python script that displays a random image 
> (image1, image2, image3....).
> All I want to do do is generate a random number which is concatenated to 
> the end of the context attribute similar to this example in PHP:
> 
> $randomNumber = ***some random number***
> return context.{'image'.$randomNumber}
> 
> Is this possible (and easy) in Python?
> 
> Thanks,
> Michael LaPera
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>