python - import module within loop -


i have 1 file, let's call foo.py. couple of things, including sending data on serial port , emailing response comes back.

i have file, looks this:

iteration = 0 while true:     iteration += 1     // stuff here every time     if iteration%5 == 0:         import foo     time.sleep (100) 

i'm aware there broader problems here elegance (or lack thereof) of independent counter, putting aside - serial transmission / email works first time it's triggered. subsequent loops @ multiple of 5 (which trigger modulo 5 == 0) nothing.

does imported version of foo.py cached, , avoid triggering on subsequent runs? if yes, how else can call code repeatedly within looping script? should include inline?

thanks tips!

if have access foo.py, should wrap whatever want run in foo.py in function. then, import foo once , call function foo.func() in loop.

see this explanation of why repeated imports not run code in file.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -