Chuck Coker wrote: > from net.grinder.script import Test > from net.grinder.script.Grinder import grinder > from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest > from HTTPClient import NVPair > connectionDefaults = HTTPPluginControl.getConnectionDefaults() > httpUtilities = HTTPPluginControl.getHTTPUtilities() > > [... snip ...] > > fileNewUserInfo = 'new-user-info.csv' > fileNewUserInfoIsOpen = 0 > > [... snip ...] > > class TestRunner: > """A TestRunner instance is created for each worker thread.""" > > # The instance initialization method. > def __init__(self): > print 'We are in TestRunner.__init__()' > global infile > global fileNewUserInfoIsOpen > if (fileNewUserInfoIsOpen == 0): > infile = open(fileNewUserInfo, "r") > fileNewUserInfoIsOpen += 1; > print 'We are inside the open if statement' > #global infile > self._userTokenCtx = '' > self._userTokenRi = '' > self._userInfo = [] > > for line in infile.readlines(): > self._userInfo.append(string.split((line),',')) > print line > > print self._userInfo > > def nextMethod(self): > > [... snip ...] > ---------------------------------------------------------------------- > > The script blows up at this line inside the for loop: > > self._userInfo.append(string.split((line),',')) > > with this error message in my error log: > > 11/2/06 7:12:20 PM (thread 0): Aborting thread due to Jython exception > "NameError: string" whilst creating per-thread test runner object > > NameError: string > File "new-user-registration.py", line 356, in __init__ > > I've tried using "import string" and it doesn't like that. I'm sure > I'm missing something very basic here due to my newness with Python. > Can anyone offer any insights?
Python's scoping is a little weird, but you're actually using it right. Adding 'import string' to the top of your module should have fixed this problem, but that's old (like Py 2.1, I think) behavior. Nowadays, you can write e.g., self._userInfo.append(",".split(line)). Also, there's a CSV module that will take care of reading and splitting CSV files for you. Personally, I would write this all out a little differently, taking advantage of the fact that performing operations in the global context is allowed: ... import csv ... userInfo = csv.reader(file('new-user-info.csv', 'rb')) class TestRunner: def __init__(self): for row in userInfo: # row is a tuple of cells print row hopefully that helps. Dustin _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor