can try expect have if else.

Ian Kelly ian.g.kelly at gmail.com
Sun Feb 21 14:22:02 EST 2016


On Feb 21, 2016 9:13 AM, "Ganesh Pal" <ganesh1pal at gmail.com> wrote:
>
> Hi Team,
>
> Iam on python 2.6 , need input on the below piece of code.

Python 2.6 isn't supported and hasn't been since October 2013. Is there
something preventing you from upgrading to 2.7?

> EXIT_STATUS_ERROR=1
>
> def create_dataset():
>     """
>      """

Empty docstring is pointless.

>     logging.info("Dataset create.....Started !!!")

This is just a pet peeve of mine, but do info-level log messages really
need triple exclamation marks?

>     try:
>         if os.path.ismount("/nfs_mount"):
>             touch_file("inode_fixcrc.txt")

Is this file really meant to be created in the current working directory,
or is it supposed to be inside the /nfs_mount?

>             logging.info("Dataset create.....Done !!!")
>         else:
>             raise Exception("/nfs_mount is not mounted. Dataset create
> failed !!!")
>             return False
>     except Exception as e:
>             logging.error(e)
>             sys.stderr.write("Dataset create failed...Exiting !!!")
>             sys.exit(EXIT_STATUS_ERROR)
>     return True
>
> 1. Can we have if else with in a try except block

Yes, of course.



More information about the Python-list mailing list