here I want to call web service function only once throughout the program. how to accomplish this anybody suggest me
import sys,osdef web_service(macid):# do somethingif "__name__" = "__main__" :web_service(macid)
here I want to call web service function only once throughout the program. how to accomplish this anybody suggest me
import sys,osdef web_service(macid):# do somethingif "__name__" = "__main__" :web_service(macid)
This is how I would to that:
i_run_once_has_been_run = Falsedef i_run_once(macid):global i_run_once_has_been_runif i_run_once_has_been_run:return# do somethingi_run_once_has_been_run = True
@Vaulstein's decorator function would work too, and may even be a bit more pythonic - but it seems like a bit overkill to me.