Gadfly Question: TypeError on __Init__
David
invalid.address at 127.0.0.1
Fri Jun 23 21:08:16 EDT 2000
What on earth is going wrong with this? I *HAD* it working, and then I
tried to make it a singleton class, and now I can't even get it back to
original form. ARRRRGH, how frustrating!
Please tell why I keep getting a TypeError: __Init__ should return None!
And if you can do this as a singleton, or make it otherwise better (ie. I
don't think I should have to create/delete a table just to get the .GFD
file to appear -- the docs indicate that as soon as the .startup method is
called, files will be created ... but not that I noticed in practice.)
====
import gadfly, os, os.path
class DBase:
def __init__(self, path, dbase):
try:
if not os.path.isdir(path):
print "creating database directory: "+path
os.mkdir(path)
if not os.path.isfile(path+"/"+dbase+".gfd"):
print "creating database file: "+dbase
connection = gadfly.gadfly()
connection.startup(dbase, path)
cursor = connection.cursor()
cursor.execute("CREATE TABLE deletemenow (i integer)")
cursor.execute("DROP TABLE deletemenow")
connection.commit()
connection = gadfly.gadfly(dbase, path)
except:
return 0
else:
return connection
# stand-alone testing
if __name__ == "__main__":
connection = DBase("test", "testdb")
cursor = connection.cursor()
cursor.execute("create table ph (nm varchar, ph varchar)")
cursor.execute("insert into ph(nm, ph) values ('arw', '3367')")
cursor.execute("select * from ph")
for x in cursor.fetchall():
print x
print ("arw", "3367")
connection.commit()
More information about the Python-list
mailing list