N
nephish
ello there. i am having a problem getting a module to work right.
i wrote a class that is going to be used in a few different scripts in
the same directory.
it looks like this:
#!/usr/bin/python
import MySQLdb
class DbConnector(object):
"""
Database Connection object.
class receives the db argument to specify the database.
"""
def __init__(self, db='test_db', host="10.10.10.16",user="me",
passwd="mypass"):
self.host = host
self.user = user
self.passwd = passwd
self.db = db
# Unpack Other Database Arguments Here
self.CreateConnection()
def createConnection(self):
self.connection = MySQLdb.connect(self.host, self.user, self.passwd,
self.db)
def killConnection(self):
self.connection.close()
def getMany(self, sql_statement):
cursor = self.connection.cursor()
try:
cursor.execute(sql_statement)
result = cursor.fetchall()
self.connection.close()
return result
except:
self.connection.close()
the file is saved as DbConnector.py and made executable.
then i get this in idle
then it tells me that the module object is not callable.
this works though
it tells me that the module has no attribute getOne.
i am really not trying for an attribute, but a method.
anyone know what i am doing wrong?
thanks
i wrote a class that is going to be used in a few different scripts in
the same directory.
it looks like this:
#!/usr/bin/python
import MySQLdb
class DbConnector(object):
"""
Database Connection object.
class receives the db argument to specify the database.
"""
def __init__(self, db='test_db', host="10.10.10.16",user="me",
passwd="mypass"):
self.host = host
self.user = user
self.passwd = passwd
self.db = db
# Unpack Other Database Arguments Here
self.CreateConnection()
def createConnection(self):
self.connection = MySQLdb.connect(self.host, self.user, self.passwd,
self.db)
def killConnection(self):
self.connection.close()
def getMany(self, sql_statement):
cursor = self.connection.cursor()
try:
cursor.execute(sql_statement)
result = cursor.fetchall()
self.connection.close()
return result
except:
self.connection.close()
the file is saved as DbConnector.py and made executable.
then i get this in idle
then it tells me that the module object is not callable.
this works though
it tells me that the module has no attribute getOne.
i am really not trying for an attribute, but a method.
anyone know what i am doing wrong?
thanks