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 

enter image description here

try put log = true near top of file declared, outside of methods or classes. rid of global log lines, , should accessible everywhere.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -