I am writing a PIN code system whereby a particular PIN is assigned to a solenoid lock and a series of actions should follow any correct PIN entry.
There are three files:
File1: stores the PIN numbers only (pin.py). For example:
locker_one_PIN = "2931"
File2: This file has a function that takes user PIN input and checks it against the existing PINs. When a correct PIN is entered, it triggers one of the if statements within File2 for the GUI, printing and solenoid control.
Along with the File2 “if” statements being triggered, I would like to run File3, from File2 with certain parameters (triggering the the relevant option to reset the PIN that was entered).
While I have tried many options including sys.arg (and failed), I am now trying to use “param” as was suggested to me and it seems I still don’t understand it.
Example from a particular File2 “if” statement, I am declaring the following
param = "pin_1_reset"
And then trying to use subprocess from the same “if” statement with the desired option:
subprocess.Popen(['python', 'File3.py', param])
File3 : This resets the PIN numbers upon a correct PIN being entered in File2. The reset function is as follows
file_path = path/to/the/pin.py
rand_pin = random.randint(1111, 9999)
def replacepin (file_path, search_text, rand_pin):
with fileinput.input(file_path, inplace=True) as file:
for line in file:
new_line = line.replace(search_text, str(rand_pin))
print(new_line, end="")
pin_1_reset =rand_pin = random.randint(1111, 9999)
replacepin (file_path, locker_one_PIN, str(rand_pin))
pin_2_reset =rand_pin = random.randint(1111, 9999)
replacepin (file_path, locker_two_PIN, str(rand_pin))
I realise I likely have failed spectacularly to understand how this should work but it is working, however it is resetting all three PINs at once, when I only want one at a time.
I presume I can’t create “if” statements in File3 because I am simply running the file with a certain parameter (or trying).
I know there are other ways to do this and I am looking for the simplest option. As mentioned, I tried sys.arg but also failed getting all sorts of list, tuple, and range errors.
I would be happy with whatever might work and would like to understand how it is working.