Can't instantiate class

D

David Mitchell

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.getConnection()

...

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(self):
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\htdocs\Intranet\addLink.py", line 42, in getCategories
db = DataUtil()

TypeError: 'module' object is not callable


Any idea what I'm doing wrong?

Thanks,

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top