473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

creating a variable from a function

Expand|Select|Wrap|Line Numbers
  1. from net.grinder.script import Test
  2. from net.grinder.plugin.http import HTTPRequest
  3. from HTTPClient import NVPair
  4.  
  5. log = grinder.logger.output
  6.  
  7. # Random Number Generator
  8. def randomnumber():
  9. import random
  10. number = random.randrange(1, 2000, 1)
  11. return number
  12.  
  13. # We declare a default URL for the HTTPRequest.
  14. request = HTTPRequest(url = "http://host")
  15.  
  16. # Details of HTTP request
  17. def page1():
  18. request.GET('/app')
  19. request.GET('/app/j_security_check?j_password=jr&j_username=operator@DIC')
  20. request.GET('/app/adduser.do?cn=jbloggs_%(seed)s&userPassword=jbloggs'%
  21. {'seed': randomnumber()} )
  22.  
  23. page1Test = Test(1, "First page").wrap(page1)
  24.  
  25. class TestRunner:
  26. def __call__(self):
  27. page1Test()
  28.  
  29.  
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.
Jul 18 '05 #1
1 2326
On 9 Oct 2003 07:38:53 -0700, st**********@jacobsrimell.com (steve) wrote:
Expand|Select|Wrap|Line Numbers
  1. from net.grinder.script import Test
  2. from net.grinder.plugin.http import HTTPRequest
  3. from HTTPClient import NVPair
  4. log = grinder.logger.output
  5. # Random Number Generator
  6. def randomnumber():
  7.     import random
  8.     number = random.randrange(1, 2000, 1)
  9.     return number
  10. # We declare a default URL for the HTTPRequest.
  11. request = HTTPRequest(url = "http://host")
  12. # Details of HTTP request
  13. def page1():
  14.     request.GET('/app')
  15.     request.GET('/app/j_security_check?j_password=jr&j_username=operator@DIC')
  16.     request.GET('/app/adduser.do?cn=jbloggs_%(seed)s&userPassword=jbloggs'%
  17. {'seed': randomnumber()} )
  18. page1Test = Test(1, "First page").wrap(page1)
  19. class TestRunner:
  20.     def __call__(self):
  21.         page1Test()

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 Are you running on your PC when it works, and having it run on a server
when it doesn't? Perhaps the environment on the server is not set up
the same, so that random is not found?

What happens if you run page1() manually and set request to something that will print
the GET args passed to it, e.g., if you do this (untested)

class Foo(object):
def GET(self, *args): print 'GET args = %r' % args
request = Foo()
page1()

to override request, interactively after the above, what do you get?
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 I guess it might mean it, for the context it's running in.

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

Any ideas anyone? thanks.


Try putting debug prints or log writes in your code to tell you more.

Regards,
Bengt Richter
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: jim.eggleston | last post by:
Windows doesn't have a HOME environment variable, but it does have HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically populate os.environ with HOME, where HOME =...
2
by: Jozef | last post by:
Hello, I'm trying to create a central function that runs a connection to an SQL Server database. The connection etc works, but when I try to call it, I get an error saying "Runtime-Error 91:...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
13
by: Nagib Abi Fadel | last post by:
Is it possible to create a session variable for each user in Postresql ?? Thx
8
by: MakaMaka | last post by:
Hi, I have a scope related question that I haven't been able to find an answer to anywhere. Is there a way to have a function in an imported module add variables to the scope of the calling...
10
by: connyledin | last post by:
Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file:...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
13
by: Justcallmedrago | last post by:
How would you declare and assign a variable inside a function THAT HAS THE NAME OF A PARAMETER YOU PASSED example: when you call createvariable("myvariable") it will declare the variable...
6
by: Chris Carlen | last post by:
Hi: I have an embedded system, platform: TI TMS320F2812 32-bit integer DSP. A module (.c file) contains external (to the funcs in that module) variables which are used to affect the operation...
1
by: joe_doufu | last post by:
I'm creating a page with multiple "widgets", each with its own XMLHttpRequest object, so the user can play with the widgets in parallel. The widgets are enclosed in divs with class "widget" and a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.