Passing values to a class

Jay Collins jcollin at exis.net
Wed Feb 28 03:26:32 CET 2001


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