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


Groups > comp.lang.python > #103742

Re: usage of try except for review.

From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Subject Re: usage of try except for review.
Date 2016-02-29 23:04 +0530
Message-ID <mailman.30.1456767286.20602.python-list@python.org> (permalink)
References <CACT3xuWm56OE7LpR8kBLfWfkDoU18sPcN5DRiXjr=68+Kywo8Q@mail.gmail.com> <CACT3xuXA=xy8ovTQOS9Bz06P0R1FjQ=bN4-3Pxqf3Cu7wN1dXg@mail.gmail.com> <c5r8dbplpbr62lca859i5cs5dlskfdqeuu@4ax.com>

Show all headers | View raw


On Mon, Feb 29, 2016 at 10:10 PM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:

>         Ask yourself: Will my program still work if I remove all the assert
> statements. If the answer is "No", then you should not be using an assert.

You meant if the answer is "NO" then I should be using asset ?

>         Can your "run()" raise an exception? Since you never show it to us we
> can't tell. And if it can, which ones? However, checking a return code is
> not an exceptional condition -- that's expected logic.
>

The run api is like a wrapper to sub-process module it does a Popen
run's the command and returns stdout ,err and ret. The only exception
it can raise is a timeout error.

>>        try:
>>            if not run_cmd_and_verify(cmd, timeout=3600):
>
>         Since your version of rcav() always trapped exceptions internally, this
> call will never raise an exception, so using a try: block is meaningless
>>                return False
>
>         And your conditional basically comes down to:
>
>         if False:
>                 return False:
>
>
>>        except:
>>           logging.error("Some meaningful message")
>>    logging.info("Setup and Creation ....Done !!!")
>
>         But you fall off and return Null on success...

Iam using the try expect block to loop over  the list do I have
alternatives  but would prefer the for loop because in the actual
program there are 100 of command and putting them in a list is quite
easy and running over with the same operation saves many lines of code
,  Cam I modify it something like a try except with pass in the except
? or any suggestions


    for cmd in ["mount /nfs_mount1", "mount /cifs_mount1"]:
        try:
            if not run_cmd_and_verify(cmd, timeout=3600):
                return False
        except:
                pass
    logging.info("Setup and Creation ....Done !!!")

Regards,
Ganesh

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


Thread

Re: usage of try except for review. Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-29 23:04 +0530

csiph-web