I have a function that connects to a database thats predefined. The code looks like: file1.py
def conn_db():
try:
cursor = pymysql.cursors.DictCursor
conn = pymysql.connect(host=settings.host,
user=settings.user,
password=settings.password,
db=settings.database,
port=settings.port,
cursorclass=cursor)
dbcursor = conn.cursor()
except pymysql.err.OperationalError as e:
print("Unable to make a connection to the mysql database. \n Error was:{}".format(e))
return conn, dbcursor
How can I use this function conn_db
from file1.py
in file2.py. And then call file2.py from executing python's intrepreter via python
?
Having a hard time even identifying something so basic, after several attempts.
Thank you.