From: brian z. <bz...@zi...> - 2002-01-17 04:10:32
|
Raj, Note: some lines wrapped so my line numbers might be off a bit > Sorry, I sent the wrong error message. Here is the correct one: > > I am getting the following namerror when I try to run the code below: > > Traceback (innermost last): > File "mtcxjdbcTester.py", line 31, in run > NameError: c You are trying to the instance variable 'c' to a local variable 'c' that is not previously either as a method argument or in the local block. You have already set the value of the instance variable 'c' in the constructor so it is unnecessary to do it again. For that matter, you don't need to do the first five assignments as they will all result in NameErrors, except of course for 'id' since this happens to be a Python builtin and the only reason line 30 didn't result in a NameError. > Traceback (innermost last): > File "mtcxjdbcTester.py", line 76, in run > AttributeError: 'int' object has no attribute 'incr' > > I'm not sure why line 50 didn't result in a NameError since the expression 'self.k = k' references a local variable 'k' which does not exist (AFAICT). The only reason 'self.iter' didn't raise an AttributeError is because 'iter' also happens to be a Python builtin. Nonetheless, k appears to be an integer as defined on my line 100 'k=0'. So when you get to line 76 (my line 75) it results in an AttributeError since int's have neither attributes or methods. Either you want 'k' to be of some other type which has an incr() method or you should change it to 'self.k += nrec'. I'm little confused as to how you wish to use the results of 'self.k += nrec' since you don't seem to reference them later (the instance variable that is). You will also run into errors in both run() methods because of similar issues. You do not need to reassign the instance variables since they were already assigned in the constructor. You will also need to be explicit about the referencing of instance variables such as on line 38. The variable 'pollint' does not exist in the local scope and I think you really wanted the instance variable 'self.pollint'. I think this chapter might help clear things up: http://www.python.org/doc/current/tut/node11.html. <shamless_plug> I also can't help but notice that you are doing JDBC work. I would recommend looking at zxJDBC (included in Jython2.1) as it does a lot of the heavy lifting for you, such as acquiring connections, iterating result sets and closing resources. It's also written to the DB API spec if cross-implementation development is of any interest. The documentation can be found at: http://jython.org/docs/zxjdbc.html. </shameless_plug> thanks, brian |