creating a variable from a function

steve steve.yeoman at jacobsrimell.com
Thu Oct 9 10:38:53 EDT 2003


[CODE]
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest
from HTTPClient import NVPair

log = grinder.logger.output

# Random Number Generator
def randomnumber():
	import random
	number = random.randrange(1, 2000, 1)
	return number

# We declare a default URL for the HTTPRequest.
request = HTTPRequest(url = "http://host")

# Details of HTTP request
def page1():
	request.GET('/app')
	request.GET('/app/j_security_check?j_password=jr&j_username=operator at DIC')
	request.GET('/app/adduser.do?cn=jbloggs_%(seed)s&userPassword=jbloggs'%
{'seed': randomnumber()} )

page1Test = Test(1, "First page").wrap(page1)

class TestRunner:
    def __call__(self):
        page1Test()

[/CODE]

I can't get the output from randomnumber() to input as the variable
%(seed)s in page1(). randomnumber() works ok on its own, but when it
is called it seems to be inserting the actual function into the
variable, rather than the output.

I get this error when running it:
ImportError: no module named random

(note: the 3rd and 4th line of page(1) are actually one line)

Any ideas anyone? thanks.




More information about the Python-list mailing list