Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103315
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: can try expect have if else. |
| Date | 2016-02-21 13:49 -0500 |
| Organization | IISS Elusive Unicorn |
| Message-ID | <mailman.22.1456080563.20994.python-list@python.org> (permalink) |
| References | <CACT3xuWMtxjC+6idsj_RfWVXLS-QCzQSdGaj2Kk4g4_EH9_wPA@mail.gmail.com> |
On Sun, 21 Feb 2016 21:42:18 +0530, Ganesh Pal <ganesh1pal@gmail.com>
declaimed the following:
>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
The return will never be reached -- executing "raise" will result in an
immediate transfer to ...
> except Exception as e:
... this exception handler...
> logging.error(e)
> sys.stderr.write("Dataset create failed...Exiting !!!")
> sys.exit(EXIT_STATUS_ERROR)
... which forcibly exits the program.
> return True
As a result, this True is of no real use. If the function doesn't
succeed, the program kills itself; the only way a caller gets control back
is when the function succeeds, so there is no need to test for success.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: can try expect have if else. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-02-21 13:49 -0500
csiph-web