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


Groups > comp.lang.python > #103301

can try expect have if else.

From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Subject can try expect have if else.
Date 2016-02-21 21:42 +0530
Message-ID <mailman.11.1456071141.20994.python-list@python.org> (permalink)

Show all headers | View raw


Hi Team,

Iam on python 2.6 , need input on the below piece of code.


EXIT_STATUS_ERROR=1

def create_dataset():
    """
     """
    logging.info("Dataset create.....Started !!!")
    try:
        if os.path.ismount("/nfs_mount"):
            touch_file("inode_fixcrc.txt")
            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
2. How can the above code be improved

Regards,
Ganesh

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


Thread

can try expect have if else. Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-21 21:42 +0530
  Re: can try expect have if else. Steven D'Aprano <steve@pearwood.info> - 2016-02-22 21:36 +1100

csiph-web