how to make the below code look better

Ganesh Pal ganesh1pal at gmail.com
Wed Dec 2 07:11:21 EST 2015


Hello team,

I need suggestion to improve the below code , Iam on Linux and python 2.7

if not os.path.ismount("/tmp"):
           sys.exit("/tmp not mounted.")
else:
     if  create_dataset() and check_permission():
     try:
          run_full_back_up()
          run_partial_back_up()
    except Exception, e:
            logging.error(e)
            sys.exit("Running backup failed")
    if not validation_errors():
        sys.exit("Validation failed")
    else:
        try:
            compare_results()
        except Exception, e:
               logging.error(e)
               sys.exit("Comparing result failed")

Question 1:

1.  if  create_dataset() and check_permission():
    Iam assuming that if statement will be executed only if both the
functions are true ?

2. Can I have a if statement within  if else ? , some how I feel its messy

3.  Any other suggestion ? please



More information about the Python-list mailing list