The Little Guy Posted June 26, 2009 Share Posted June 26, 2009 Here is the basic of what I have: main.py from Table import Table if __name__ == "__main__": pb = Pybase("myDatabase") pb.delTbl("myDB") Pybase.py import os class Pybase: dirLocation = "C:\\Users\\Administrator\\Desktop\\Database\\data\\" workDB = "" def __init__(self, db = ""): loc = self.dirLocation + db if os.path.exists(loc): self.workDB = loc else: print "Database: " + db + " does not exist." def mkDB(self, db): loc = self.dirLocation + db if os.path.exists(loc): print "Database: " + db + " already exists." else: os.mkdir(loc) print "Database: " + db + " created successfully." def delDB(self, db): loc = self.dirLocation + db if os.path.exists(loc): os.rmdir(loc) print "Database: " + db + " deleted successfully." else: print "Database: " + db + " does not exist." Table.py from Pybase import Pybase class Table(Pybase): def __init__(self): val = '' def mkTbl(self, tbl): loc = self.workDB + tbl if os.path.exists(loc): print "Table: " + tbl + " already exists" else: print "Table: " + tbl + " created successfully" def delTbl(self, tbl): print "" I'm not sure I understand why it is saying: Traceback (most recent call last): File "C:\Users\Administrator\Desktop\Database\main.py", line 3, in <module> pb = Pybase("myDatabase") NameError: name 'Pybase' is not defined I thought I was doing inheritance correctly, but I guess not, does anyone know the proper way to do this? Thanks! Link to comment https://forums.phpfreaks.com/topic/163733-python-inheritance-help/ Share on other sites More sharing options...
corbin Posted June 26, 2009 Share Posted June 26, 2009 In Python 3.0, print is a function, not a construct. (It just took me like 20 minutes to figure that out haha.) http://docs.python.org/library/2to3.html May be of use to you if you have a lot of Python 2 code and don't want to recode or switch to Python 2. Link to comment https://forums.phpfreaks.com/topic/163733-python-inheritance-help/#findComment-863973 Share on other sites More sharing options...
The Little Guy Posted June 26, 2009 Author Share Posted June 26, 2009 Yeah, I know... I'm using python 2.5, so I don't need to worry about that Sorry I didn't say that b4 Link to comment https://forums.phpfreaks.com/topic/163733-python-inheritance-help/#findComment-864121 Share on other sites More sharing options...
The Little Guy Posted June 26, 2009 Author Share Posted June 26, 2009 I got it! I don't know how but I got it! Link to comment https://forums.phpfreaks.com/topic/163733-python-inheritance-help/#findComment-864125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.