Hello,
all of this makes absolute sense and I slowly realised last night after I posted. Then I started looking for ways to force some sort of reimport in the same if statement after the say PIN1 had been checked, used and reset.
The flow of events is like this:
-the PINS.py file exists and contains pin numbers only as per below
-as per the code you've already seen, the pin is entered by the user in the tkinter gui and then is checked by that code
(The additional line of code that I hadn't yet posted is)
-this opens the pin reset script, which also imports PINS.py in order to identify and reset them
- the pin reset script writes a new random pin to PINS.py for whichever pin was used and now the new pin is in PINs.py along with the so far unused pin numbers
-all the while the main GUI code is in a loop with from PINS import lPIN1, PIN2 but as you mentioned, it only loads the data once, when initiated and I need it to reload the import for all, or at least that one pin that was used and subsequently reset
So as the last set instructions afterI need to force it to take on the newly set pin. In VS code I see the newly generated pin number updated within a fraction of a second but I am not sure how long it would take python to get this update. I tried to create a function that would reimport but it didn't work.
When I tried using I did the following
While I saw no errors in terminal output, I still could not use the new pin that was set as the variable PIN1 is still holding onto the old pin. Perhaps it is a timing issue or I am using importlib.reload() incorrectly. Then I tried creating a function external to the pin_check function and called it at the end of the if statement
but this didn't work either. My code is made up of many separate scripts so I think the above should be more useful to get an idea of how it is working.
all of this makes absolute sense and I slowly realised last night after I posted. Then I started looking for ways to force some sort of reimport in the same if statement after the say PIN1 had been checked, used and reset.
The flow of events is like this:
-the PINS.py file exists and contains pin numbers only as per below
Code:
PIN1 = "9464"PIN2 = "7240"PIN3 = "8911"Code:
elif value == '#': if pin == PIN1: print("PIN1 OK") pin = '' e.delete('0', 'end') subprocess.Popen(['python', 'pin_reset.py'])(The additional line of code that I hadn't yet posted is)
Code:
subprocess.Popen(['python', 'pin_reset.py']) Code:
from PINS import lPIN1, PIN2, PIN3-all the while the main GUI code is in a loop with from PINS import lPIN1, PIN2 but as you mentioned, it only loads the data once, when initiated and I need it to reload the import for all, or at least that one pin that was used and subsequently reset
So as the last set instructions after
Code:
subprocess.Popen(['python', 'pin_reset.py'])When I tried using
Code:
importlib.reload()Code:
import PINS import importlib elif value == '#': if pin == PIN1: print("PIN1 OK") pin = '' e.delete('0', 'end') subprocess.Popen(['python', 'pin_reset.py']) importlib.reload(PINS)Code:
def reload_pins(): importlib.reload(PINS)Code:
elif value == '#': if pin == PIN1: print("PIN1 OK") pin = '' e.delete('0', 'end') subprocess.Popen(['python', 'pin_reset.py']) reload_pins()Statistics: Posted by Furutsu — Thu Dec 11, 2025 11:35 am