I'm new to Python. Only been coding a month. I am stumped. The below code works perfectly until I move it to a function. I'm not at work so I can't remember the exact error, but it was something about no temp registry access. The exact error is not important since the code is working. What I can't figure out is why I can't call this code from a function. I can import this code with 'from filename.py import *' and it works.
Can an experienced Python coder explain why the access connection will not work in a function call?
import pypyodbc
gage_list = []
gage=0
ser_num=1
owner=2
duedate=3
status=4
#create connection
DBfile = "C:/ProgramData/CyberMetrics Corporation/GAGEtrak 7.0/AppFiles/Gtw70.accdb"
conn = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+DBfile)
cursor = conn.cursor()
cursor.execute("SELECT Gage_ID FROM Gage_Master")
Gage_ID=cursor.fetchall()
cursor.execute("SELECT Gage_SN FROM Gage_Master")
Gage_SN=cursor.fetchall()
cursor.execute("SELECT GM_Owner FROM Gage_Master")
GM_Owner=cursor.fetchall()
cursor.execute("SELECT Next_Due_Date FROM Gage_Master")
Next_Due_Date=cursor.fetchall()
cursor.execute("SELECT Status FROM Gage_Master")
Status=cursor.fetchall()
conn.close()
counter = 0
for i in range(len(Gage_ID)): #combines gage columns into an array
tup = Gage_ID[i][0], Gage_SN[i][0], GM_Owner[i][0], Next_Due_Date[i][0], Status[i][0]
gage_list.append(tup)
print(gage_list[14][duedate]) #to choose a field, select from gage, ser_num, owner, duedate, or status variables