1

I want to write a script for automation of sequence of events, where the execution of the next sequence depends upon the success of the previous step. There are basically 8 functions which I want to call onne by one and if one fails, I want to exit at that point. So how can i handle this in python?

8
  • Python is already imperative. What's the problem? Do you want some fancy chaining? Commented Dec 19, 2014 at 15:16
  • Here at SO, we suggest, improve and help you along the way. We don't write code for you. Commented Dec 19, 2014 at 15:17
  • if-else statement can do what you want Commented Dec 19, 2014 at 15:17
  • 1
    Perhaps you're looking for exceptions? Commented Dec 19, 2014 at 15:20
  • 1
    @Jonathan: if there is something from your experience that you could share for handling situations like this gracefully in python, you are welcome. Also, its pretty apparent from the question that I am not expecting any code Commented Dec 19, 2014 at 15:24

2 Answers 2

2

Basic if, and elif statements can overcome your needs.

Say you had a function that returned a variable.

def f(z):
    data = z
    return data

You can analyse the result with a if. Assign a new variable to the function f:

x = f(0)
if x == 0:
    #do something

So if x is equal to 0, continue with code. But what is c = 1?

import os
x = f(1)
if c != 0:
    os._exit(0)

os._exit(0) quits the program.

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

Comments

0

I highly recommend taking a look at pytest (or one of the other Python testing frameworks).

This guide should get you up and running quickly:

http://pytest.org/latest/getting-started.html

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.