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


Groups > comp.lang.python > #103310 > unrolled thread

Re: can try expect have if else.

Started byGanesh Pal <ganesh1pal@gmail.com>
First post2016-02-21 23:09 +0530
Last post2016-02-21 23:09 +0530
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: can try expect have if else. Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-21 23:09 +0530

#103310 — Re: can try expect have if else.

FromGanesh Pal <ganesh1pal@gmail.com>
Date2016-02-21 23:09 +0530
SubjectRe: can try expect have if else.
Message-ID<mailman.17.1456076380.20994.python-list@python.org>
On Sun, Feb 21, 2016 at 10:37 PM, Ben Finney <ben+python@benfinney.id.au> wrote:

> What result do you get when running that code? What empirical reason do
> you have to think it would work or not work?

I wanted to know was is it good to have if else with in a try expect
block ,  I was checking more from the programming perspective  and if
I need to avoid it and if its recommended

>> 2. How can the above code be improved
>
> The following sequence of statements::
>
>     raise Exception("/nfs_mount is not mounted. Dataset create failed !!!")
>     return False
>
> do not make sense. The ‘return‛ statement will never be reached. So your
> intent must be something other than what is expressed by that code.
>

 I was using it with create_data function in the below code .  If
create_dataset failed the exception would be caught  , I think you are
right I need not worry about returning False

    functions = [create_logdir, create_dataset]
    for func in functions:
        try:
            func()
        except Exception as e:
            logging.error(e)
            return False

Regards,
Ganesh

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web