Global file variable inaccessible outside function (Python) -
the variable log opens file timestamp when button pressed, , should closed when button off. however, cannot close file opened in function, when file has been declared global. tried putting "global file" outside of both functions, did not work.
if button_status==true: #press start if first_run==true: #start new logfile global log log=open(fname,'a') log.writelines(header) first_run=false #other code here if button_status==false:#press stop log.close() first_run=true 
try put log = true near top of file declared, outside of methods or classes. rid of global log lines, , should accessible everywhere.
Comments
Post a Comment