Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Running multiple scripts in sequence in Python

I am running multiple scripts in sequence according to the list I and the following executable. However, when one of the script in folder (say, 2) runs into an error, it terminates instead of moving to folder 3. Basically I want the executable to move onto the next script if there is an error in the present script. How do I do this?

I=[1,2,3]
for i in I: 
    exec(open(rf"C:\5100 nodes\{i}\5100_beta_0.01_50.0_1.0ND_3.py").read())

The error encountered while running script in folder 2 is

File "<string>", line 618, in <module>

ValueError: max() arg is an empty sequence

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could use a try-except block.

I=[1,2,3]
for i in I:
    try: 
        exec(open(rf"C:\5100 nodes\{i}\5100_beta_0.01_50.0_1.0ND_3.py").read())
    except Error as e:
        print(e)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading