Passing values to a class
Bruce Wolk
bawolk at ucdavis.edu
Tue Feb 27 22:40:21 EST 2001
Jay,
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.
Bruce
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
> pass
> def createdb(self):
> d = dbm.open(base,"n")
> d['name'] = "Jim Smith"
> d.close()
>
> app = db("databse")
> app.createdb()
>
> 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
mailing list