RE: [Zope] Random Module

2005-08-26 Thread Aaron Bauman
From ZopeBook 2.6:
quote
Using a module usage (pick a random choice from a list):

span tal:replace=python:modules['random'].choice(['one',
'two', 'three', 'four', 'five'])
a random number between one and five
/span
/quote

Substitute any list you wish...

to generate a random number [ 0  x  1 ), you'd just use something like
quote
tal:define define=random_floating_point_number
python:modules['random'].random() /
/quote

I'd be curious to know if the random() method DOESN't work, 
cause the choice method has definitely worked for me...

Hope it helps,
-
Aaron Bauman
http://www.gaycenter.org



-Original Message-
From: David Siedband [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 25, 2005 2:38 PM
To: ZOPE.org
Subject: Re: [Zope] Random Module

Are you sure you can't import the functions you need?  It might be
worthwhile to see if what you want to do can be done without adding to your
allowed modules.  That should be kind of a last resort.  I'm curious what
kind of functionality you need from random that can't be done within the
importable functions...
--
David


On Aug 25, 2005, at 10:36 AM, Sam Boggess wrote:

 Why won't Zope let me call the random module?  It's really annoying to 
 have to write an external method to call such a simple tool.  Is there 
 a way around this?  Thanks.



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Random Module

2005-08-26 Thread Sam Boggess
My bad, Zope does allow the random module, was just importing and 
refering to it wrong in my script:


#Bad:
from random import *
randomNum = random()

#Good:
import random
randomNum = random.random()


Thanks for all you help.


Aaron Bauman wrote:


From ZopeBook 2.6:

quote
Using a module usage (pick a random choice from a list):

span tal:replace=python:modules['random'].choice(['one',
'two', 'three', 'four', 'five'])
a random number between one and five
/span
/quote

Substitute any list you wish...

to generate a random number [ 0  x  1 ), you'd just use something like
quote
tal:define define=random_floating_point_number
python:modules['random'].random() /
/quote

I'd be curious to know if the random() method DOESN't work, 
cause the choice method has definitely worked for me...


Hope it helps,
-
Aaron Bauman
http://www.gaycenter.org



-Original Message-
From: David Siedband [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 25, 2005 2:38 PM

To: ZOPE.org
Subject: Re: [Zope] Random Module

Are you sure you can't import the functions you need?  It might be
worthwhile to see if what you want to do can be done without adding to your
allowed modules.  That should be kind of a last resort.  I'm curious what
kind of functionality you need from random that can't be done within the
importable functions...
--
David


On Aug 25, 2005, at 10:36 AM, Sam Boggess wrote:

 

Why won't Zope let me call the random module?  It's really annoying to 
have to write an external method to call such a simple tool.  Is there 
a way around this?  Thanks.
   






 



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


RE: [Zope] Random Module

2005-08-25 Thread Jim Abramson
You can keep all the modules/types/etc you want Zope to stop hassling
you about into a single file, restart Zope, and enjoy life again.

create a Product called whatever you like (we called ours
'GlobalModules')...

our looks like this:

in Products/GlobalModules: __init__.py

# Global module assertions for Python scripts
from Products.PythonScripts.Utility import allow_module
from AccessControl import allow_module, allow_class, allow_type

allow_module('re')
import re
allow_type(type(re.compile('')))
allow_type(type(re.match('x','x')))

allow_module('zipfile')
import zipfile
allow_class(zipfile.ZipFile)
allow_class(zipfile.ZipInfo)

END--


For you, obviously, you'll want to allow_module('random'), perhaps
declare some of its own special types, etc...

hth
Jim



 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On 
 Behalf Of Sam Boggess
 Sent: Thursday, August 25, 2005 1:36 PM
 To: zope@zope.org
 Subject: [Zope] Random Module
 
 Why won't Zope let me call the random module?  It's really 
 annoying to have to write an external method to call such a 
 simple tool.  Is there a way around this?  Thanks.
 ___
 Zope maillist  -  Zope@zope.org
 http://mail.zope.org/mailman/listinfo/zope
 **   No cross posts or HTML encoding!  **
 (Related lists -
  http://mail.zope.org/mailman/listinfo/zope-announce
  http://mail.zope.org/mailman/listinfo/zope-dev )
 
 
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Random Module

2005-08-25 Thread David Siedband
Are you sure you can't import the functions you need?  It might be 
worthwhile to see if what you want to do can be done without adding to 
your allowed modules.  That should be kind of a last resort.  I'm 
curious what kind of functionality you need from random that can't be 
done within the importable functions...

--
David


On Aug 25, 2005, at 10:36 AM, Sam Boggess wrote:

Why won't Zope let me call the random module?  It's really annoying to 
have to write an external method to call such a simple tool.  Is there 
a way around this?  Thanks.


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )