Jump to content

Python inheritance help


Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.