T. Crane wrote: > Hi, > > If I define a class like so: > > class myClass: > import numpy > a = 1 > b = 2 > c = 3 > > def myFun(self): > print a,b,c > return numpy.sin(a) > > > I get the error that the global names a,b,c,numpy are not defined. Fairly > straightforward. But if I am going to be writing several methods that keep > calling the same variables or using the same functions/classes from numpy, > for example, do I have to declare and import those things in each method > definition? Is there a better way of doing this? > > thanks, > trevis > >
Put the import at the top level, and you forgot self when accessing attributes. import numpy class myClass: a=1 b=2 c=3 def myFun(self): print self.a, self.b, self.c return numpy.sin(a) -- http://mail.python.org/mailman/listinfo/python-list