Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103742
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ganesh Pal <ganesh1pal@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: usage of try except for review. |
| Date | Mon, 29 Feb 2016 23:04:44 +0530 |
| Lines | 54 |
| Message-ID | <mailman.30.1456767286.20602.python-list@python.org> (permalink) |
| References | <CACT3xuWm56OE7LpR8kBLfWfkDoU18sPcN5DRiXjr=68+Kywo8Q@mail.gmail.com> <CACT3xuXA=xy8ovTQOS9Bz06P0R1FjQ=bN4-3Pxqf3Cu7wN1dXg@mail.gmail.com> <c5r8dbplpbr62lca859i5cs5dlskfdqeuu@4ax.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de GNUeojDLd/YfVeFro46w7wC0GRCSBCO/yPRLCqdvSsmg== |
| Return-Path | <ganesh1pal@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'modify': 0.04; '"no"': 0.07; 'except:': 0.07; 'skip:/ 10': 0.07; 'wrapper': 0.07; 'api': 0.09; 'cc:addr:python-list': 0.09; 'alternatives': 0.09; 'cmd': 0.09; 'exception,': 0.09; 'meaningful': 0.09; 'stdout': 0.09; 'timeout': 0.09; 'exception': 0.13; '2016': 0.16; 'conditional': 0.16; 'exception?': 0.16; 'false:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:usage': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'try:': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'meant': 0.22; 'exceptions': 0.22; 'pass': 0.22; 'feb': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; 'command': 0.26; 'checking': 0.27; 'message- id:@mail.gmail.com': 0.27; 'actual': 0.28; 'raise': 0.29; 'code': 0.30; 'putting': 0.30; 'saves': 0.30; 'error.': 0.31; "can't": 0.32; 'run': 0.33; 'null': 0.33; 'except': 0.34; 'running': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'quite': 0.35; 'something': 0.35; 'expected': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'creation': 0.38; 'version': 0.38; 'received:209': 0.38; 'does': 0.39; 'still': 0.40; 'easy': 0.60; 'your': 0.60; 'show': 0.62; 'fall': 0.66; '100': 0.79; 'message")': 0.84; 'subject:try': 0.84; 'dennis': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=AoeFXjv8w9SqFeSgcjSy4jDpxG6eI9cVhyTYcQS+k2o=; b=KWIx6p/puFusxC3W91gGsRgiSL3hT7vSqqbnHJ7x1MauGeK8EQLc7K4uRCabeb2FnF xQFDErP7NyBGqLFnSnuONyOo0ycNVNPtAUwHSopeVPg7U3lefl4MIuXZflFJ6lnpnZI/ aSrvJMoWN0NoMnSJKNu9iEj91ShYgE53URFKH3IlY96o6CfNdonoElvXq4jlrxiHoMPb 3mdqdup+Qwn31RtFBsZQ4LFN5ysHTNjlAQhu1rnDojtR4qZSE+pLmzM4DUk0KGR+7a8M x7mgRjT7jFIP6oaJpoYp0VaTErpDTfr3V3cvCkDvjdDq8Ola0co5iqYva53326QfVdwY dbXQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=AoeFXjv8w9SqFeSgcjSy4jDpxG6eI9cVhyTYcQS+k2o=; b=WRIvHfMqEtzIRquz+7k5EkDM6xUXP5FwlrEy5tvm8QUBU2VxA0zfcukesF0HoBWZcc pa3V2nm4SBrVdCONuPpyShbAkK5dOOey0xa15SDDcnLWdX7QkWmVK3BJ3C3pmococpnL TyOEL5SKmykXdO1Z78fD5xE9AGco/T8A634h+pdluk2MimiEUElOac0AzyrDMsBW0Cu6 jDYbrhTH+4JEmIal2ZYiS2LgzRQi918J09JKEVIKlfk8NE2u1eM5mOhLxIla4sTssvnf TnTnYP/Cc4B51HRXQc4Njo2GrrON41oiRzSwECUdF5JBsx52JZ2892nt5c9N6zbKxPCN c75Q== |
| X-Gm-Message-State | AD7BkJI1uK/+L/DjH9eBl2nI6yc+p5DEz9m+HvZXpL8OGwGtxhaz90CTnc2+baB15pAsHIEsy0O3KAVTAWHHAA== |
| X-Received | by 10.25.167.74 with SMTP id q71mr6126530lfe.24.1456767284585; Mon, 29 Feb 2016 09:34:44 -0800 (PST) |
| In-Reply-To | <c5r8dbplpbr62lca859i5cs5dlskfdqeuu@4ax.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:103742 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: usage of try except for review. Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-29 23:04 +0530
csiph-web