how to make the below code look better
me
self at example.org
Wed Dec 2 10:23:55 EST 2015
On 2015-12-02, Ganesh Pal <ganesh1pal at gmail.com> wrote:
> 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")
Apart from what already mentioned (indentation, assumptions on
environment):
> 1. if create_dataset() and check_permission():
> Iam assuming that if statement will be executed only if both the
> functions are true ?
Yes, this is the meaning of 'and'.
Notice how functions are always true, but the result of the function call
might not be.
- create_dataset is a function.
- create_dataset() is a function call.
> 2. Can I have a if statement within if else ? , some how I feel its messy
You are searching for `elif`.
More information about the Python-list
mailing list