May I ask which condition I should use to check the files A or B or both exist then execute the expression A or B or Both?
if or while or try...
>Solution :
I would test if they both exist first, something like
if fileA exists:
if fileB exists:
both_exist = True
else:
file_A_exists = True
elif fileB exists:
file_B_exists = True
Of course that code doesn’t actually work, but it gives an idea of where you would want to check for files existing. A good command you can use to check if a file exists is os.path.exists(fileA) but you will need to import os.
And then, if you want to execute the code, all you have to do is run the correct command next to the variable line, so:
Line 3-5:
both_exist = True
os.system('python fileA.py')
os.system('python fileB.py')
That would be for python, and you’d have to import os to actually run the os.system(‘python’) command.
