Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99895

Re: how to make the below code look better

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail
From me <self@example.org>
Newsgroups comp.lang.python
Subject Re: how to make the below code look better
Date Wed, 2 Dec 2015 15:23:55 +0000 (UTC)
Organization Aioe.org NNTP Server
Lines 37
Message-ID <n3n2eb$uaj$1@speranza.aioe.org> (permalink)
References <mailman.120.1449058284.14615.python-list@python.org>
NNTP-Posting-Host 9qAAUSICBkcuS8jRtpWC7g.user.speranza.aioe.org
X-Complaints-To abuse@aioe.org
User-Agent slrn/1.0.2 (Linux)
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.python:99895

Show key headers only | View raw


On 2015-12-02, Ganesh Pal <ganesh1pal@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`.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

how to make the below code look better Ganesh Pal <ganesh1pal@gmail.com> - 2015-12-02 17:41 +0530
  Re: how to make the below code look better BartC <bc@freeuk.com> - 2015-12-02 12:20 +0000
    Re: how to make the below code look better Chris Angelico <rosuav@gmail.com> - 2015-12-02 23:31 +1100
  Re: how to make the below code look better Steven D'Aprano <steve@pearwood.info> - 2015-12-03 00:28 +1100
    Re: how to make the below code look better Chris Angelico <rosuav@gmail.com> - 2015-12-03 00:49 +1100
  Re: how to make the below code look better me <self@example.org> - 2015-12-02 15:23 +0000

csiph-web