If statement with or operator

alister alister.ware at ntlworld.com
Wed Feb 22 12:25:20 EST 2017


On Wed, 22 Feb 2017 22:33:31 +0530, Ganesh Pal wrote:

> Hello Friends,
> 
> I  need suggestion on the if statement in the below code  , all that I
> was trying to do was to add a check  i.e if any one of the functions
> return True then  break the loop.
> 
> 
>  end_time = time.time() + 300
>     umount_completed = False while time.time() < end_time:
>         if attempt_umount() is True or df_output_lines() is True:
>            logging.info("umount completed sucessfully")
>            umount_completed = True break
>         time.sleep(15)
>     assert umount_completed, "ERROR: The umount failed Exiting"
> 
> Can this be optimized better  , please suggest.  I am on Linux and
> Python 2.7
> 
> 
> Regards.
> Ganesh

a simple
 if attempt_umount() or df_output_lines():

would suffice
(Q argument on whether the unnecessary is True makes the code more 
readable or not)

there may also be better ways to perform your unmount but without knowing 
the details of the code it is difficult to say 



-- 
"Nuclear war would really set back cable."
- Ted Turner



More information about the Python-list mailing list