0

I am really new to Python. I would like to create a logical loop for my python script where when the program stuck it will automatically jump to next line and continue the program.

Here is an example of my code which was a series of different combination of parameter values. I am aware that some combinations of parameter may crash the program that's why I want to have a Error Handling loop to keep the program running.

   ini_file="model-simulation fL=0.1,fks=1,fno=1,fnc=1,fr=1,fs=1.ini"; pytopkapi.run(ini_file)
   ini_file="model-simulation fL=0.1,fks=6,fno=1,fnc=1,fr=1,fs=1.ini"; pytopkapi.run(ini_file)
   ini_file="model-simulation fL=0.1,fks=11,fno=1,fnc=1,fr=1,fs=1.ini"; pytopkapi.run(ini_file)
   ini_file="model-simulation fL=0.1,fks=16,fno=1,fnc=1,fr=1,fs=1.ini"; pytopkapi.run(ini_file)
   ini_file="model-simulation fL=0.1,fks=21,fno=1,fnc=1,fr=1,fs=1.ini"; pytopkapi.run(ini_file)
   ini_file="model-simulation fL=0.1,fks=26,fno=1,fnc=1,fr=1,fs=1.ini"; pytopkapi.run(ini_file)

Sometimes it will have error messages like the following picture which stops the whole program. Could someone please help me out? enter image description here

4
  • 1
    I have no idea what you mean by a "logical loop". Commented Jul 4, 2014 at 9:03
  • 1
    Sorry for the confusion, what I mean is this loop can detect if the program has stopped running or not? If has stopped, it can move to next line of the script. Commented Jul 4, 2014 at 9:05
  • What do you mean "stopped"? If the program has stopped, how can it do anything? If you are talking about error handling, read the tutorial. Commented Jul 4, 2014 at 9:27
  • Yeah, I think it might be called error handing in python. Never heard this term but thanks a lot. Commented Jul 4, 2014 at 9:48

1 Answer 1

2

Well you could catch the exceptions then continue after by doing:

ini_files = ["model-simulation fL=0.1,fks=1,fno=1,fnc=1,fr=1,fs=1.ini",
             "model-simulation fL=0.1,fks=6,fno=1,fnc=1,fr=1,fs=1.ini"]
for ini in ini_files:
    try:
        pytopkapi.run(ini)
    except Exception as e:
        print(e)  # If you want to see your error

See Error Handling documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.