Passing values to a class
bawolk at ucdavis.edu
Wed Feb 28 04:40:21 CET 2001
You are right that the scope is wrong. In __init__ add the statement
self.base = base and in createdb use self.base instead of base.
Jay Collins wrote:
> Anyone shed some light on what I'm doing stupid/wrong here:
> import dbm
> class db:
> def __init__(self,base):
> print "using database",base
> def createdb(self):
> d = dbm.open(base,"n")
> d['name'] = "Jim Smith"
> app = db("databse")
> how come createdb() doesn't see base? Maybe I'm not getting class scope
> correctly. My idea was to pass what database I wanted to work on for that
> instance. Then I could call the methods to do work on the data in it.
More information about the Python-list