Can't instantiate class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Mitchell

    #1

    Can't instantiate class

    Hello,

    Here is a very basic question, but it is frustrating me to no end
    nonetheless.

    I have one file called addLink.py. In a method in this file I am trying
    to instantiate a class and call a method from that class. Here is the code:

    def getCategories() :
    # instantiate the DataUtil class
    db = DataUtil()
    # and call the getConnection() method
    connection = db.getConnectio n()

    ...

    At the top of this file I am importing the DataUtil module (named
    DataUtil.py) with this line:

    import DataUtil

    The DataUtil.py file resides in the same directory as the above file and
    looks like this:

    import MySQLdb

    class DataUtil:
    def __init__(self):
    print "init"

    def getConnection(s elf):
    return MySQLdb.connect (host="host", user="user", passwd="pass",
    db="test")

    When I execute the getCategories() method above I get the following error:

    File "C:\Apache2\htd ocs\Intranet\ad dLink.py", line 42, in getCategories
    db = DataUtil()

    TypeError: 'module' object is not callable


    Any idea what I'm doing wrong?

    Thanks,

    Dave

Working...