Reputation: 23
I'm not sure why I can't import the db_password
variable.
Running db_setup gives:
Traceback (most recent call last):
File "db_setup.py", line 5, in <module>
passwd=dbconfig.db_password)
TypeError: 'module' object is not callable
I'm missing something but i'm not sure what.
I can open up an interperter and import dbconfig
as well as call `dbconfig.db_password'
db_setup.py
import pymysql
import dbconfig
connection = pymysql.connections(host='localhost', user=dbconfig.db_user, passwd=dbconfig.db_password)
dbconfig.py
db_user='username'
db_password='password'
I expect the module to pass the variable 'password'
Upvotes: 2
Views: 181
Reputation: 5006
There is no problem with the import of db_password
variable, the error is elsewhere :
import pymysql
import dbconfig
connection = pymysql.connect(host='localhost', user=dbconfig.db_user, password=dbconfig.db_password)
pymysql.connections
is a module, not a function, and contains the Connection
class that is instanciate and returned by pymysql.connect()
The proper way to get an instance of this class is to call connect().
Upvotes: 1