Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103742 > unrolled thread
| Started by | Ganesh Pal <ganesh1pal@gmail.com> |
|---|---|
| First post | 2016-02-29 23:04 +0530 |
| Last post | 2016-02-29 23:04 +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.
Re: usage of try except for review. Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-29 23:04 +0530
| From | Ganesh Pal <ganesh1pal@gmail.com> |
|---|---|
| Date | 2016-02-29 23:04 +0530 |
| Subject | Re: usage of try except for review. |
| Message-ID | <mailman.30.1456767286.20602.python-list@python.org> |
On Mon, Feb 29, 2016 at 10:10 PM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
> Ask yourself: Will my program still work if I remove all the assert
> statements. If the answer is "No", then you should not be using an assert.
You meant if the answer is "NO" then I should be using asset ?
> Can your "run()" raise an exception? Since you never show it to us we
> can't tell. And if it can, which ones? However, checking a return code is
> not an exceptional condition -- that's expected logic.
>
The run api is like a wrapper to sub-process module it does a Popen
run's the command and returns stdout ,err and ret. The only exception
it can raise is a timeout error.
>> try:
>> if not run_cmd_and_verify(cmd, timeout=3600):
>
> Since your version of rcav() always trapped exceptions internally, this
> call will never raise an exception, so using a try: block is meaningless
>> return False
>
> And your conditional basically comes down to:
>
> if False:
> return False:
>
>
>> except:
>> logging.error("Some meaningful message")
>> logging.info("Setup and Creation ....Done !!!")
>
> But you fall off and return Null on success...
Iam using the try expect block to loop over the list do I have
alternatives but would prefer the for loop because in the actual
program there are 100 of command and putting them in a list is quite
easy and running over with the same operation saves many lines of code
, Cam I modify it something like a try except with pass in the except
? or any suggestions
for cmd in ["mount /nfs_mount1", "mount /cifs_mount1"]:
try:
if not run_cmd_and_verify(cmd, timeout=3600):
return False
except:
pass
logging.info("Setup and Creation ....Done !!!")
Regards,
Ganesh
Back to top | Article view | comp.lang.python
csiph-web