I have two scripts, qyeryfunction.py and generatecharts.py. I would like to get the results of the week_number variable from queryfunction and put them in weeks in generatecharts.py. How can I do this?
#queryfunction.py
import MySQLdb
try:
db = MySQLdb.connect("localhost","myusr","mypass","mydb")
except MySQLdb.DatabaseError:
print 'Cant connect to database, check if MySQL service is running'
class WeekQuery:
def __init__(self, name):
self.name = name
def query(self):
try:
cursor = db.cursor()
cursor.callproc(self)
results = cursor.fetchall()
week_number = [i[0] for i in cursor.description]
except MySQLdb.ProgrammingError:
print 'Data unavailable'
cursor.close()
return results
and
#generatecharts.py
from queryfunction import WeekQuery, query
#class GenerateCharts():
n = WeekQuery('my_first_query')
g = WeekQuery('my_second_query')
first_data = query(n.name)
second_data = query(g.name)
weeks = ???