Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26009
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@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; 'exception': 0.03; 'output': 0.04; 'exception.': 0.07; 'expressions': 0.07; 'false,': 0.07; 'optparse': 0.07; 'python': 0.09; 'exception,': 0.09; 'exception:': 0.09; 'received:mail-lpp01m010-f46.google.com': 0.09; 'subclass': 0.09; '--help': 0.16; '-o,': 0.16; '24,': 0.16; 'argparse': 0.16; 'ideally,': 0.16; 'subject:expressions': 0.16; 'later': 0.16; 'wrote:': 0.17; 'skip:u 30': 0.17; 'input': 0.18; 'raise': 0.24; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'compiled': 0.27; 'recognized': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'actual': 0.28; 'all.': 0.28; 'assert': 0.29; 'class': 0.29; 'received:209.85.215.46': 0.30; 'helpful': 0.30; 'code': 0.31; 'like:': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'bad': 0.37; 'option': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'more': 0.63; 'jul': 0.65; 'on...': 0.65; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=lq2Q4eQIwnvfd4sS0bwufhMXukqiGftwtI1F9VbfohI=; b=wPmbQPUVXN2B82mXE4rhS7hYh8PCgxpoJDviH0ty/4OZ4puAirLRGmxyOcndk7PzQi OqtXCCr0XEW5jzNI9YRNv1uFsCi//lgJlNKowK50Bscd9YnpMgK0q4nJ3L54BUvesyb0 U88ULLXDmHG+ZZEpS6fSejz0NDkb3/v3FZnlbbhaG3llGJsfpak/kFuf+A4Sc8Hc2U5/ lVirwXVIALrxxXZq38C0bIkYu+TYeKZc1eN24JGfA4CgiFZttnk953VssKtzCJhOTJPE yjS6tjaWyOaNfnYp7w+2xFtO8ZS/1sLpVEnppNzBd8nRReSOq23IuvBAZqIoJgVEFwuO t26g== |
| MIME-Version | 1.0 |
| In-Reply-To | <9f6bed70-1ec1-4e3e-bdd0-c96013bf7df2@googlegroups.com> |
| References | <9f6bed70-1ec1-4e3e-bdd0-c96013bf7df2@googlegroups.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Tue, 24 Jul 2012 14:31:25 -0600 |
| Subject | Re: assert expressions |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2553.1343161917.4697.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1343161917 news.xs4all.nl 6931 [2001:888:2000:d::a6]:58794 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:26009 |
Show key headers only | View raw
On Tue, Jul 24, 2012 at 1:57 PM, Wanderer <wanderer@dialup4less.com> wrote:
> If I use the code
>
> assert False, "unhandled option"
>
> I get output like:
>
> option -q not recognized
> for help use --help
>
> What other expressions can I use other than "unhandled option"? Is there a list somewhere?
Are you using argparse or optparse or getopt or something else
altogether? And where are you placing this assert? It would be
helpful to see some actual code to understand what you are doing.
And by the way, assert is a very bad way to check user input or to
unconditionally raise an exception. The reason is that if Python is
invoked with -O, then all assertions are removed from the compiled
bytecode, and then your unconditional exception code doesn't raise any
exception at all. If you want to raise an exception, just do it:
raise Exception("unhandled option")
Ideally, you would also subclass Exception to create a more specific
exception class for your custom exception:
class UnhandledOptionException(Exception):
pass
# Then, later on...
raise UnhandledOptionException("-q")
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
assert expressions Wanderer <wanderer@dialup4less.com> - 2012-07-24 12:57 -0700
Re: assert expressions Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-24 14:31 -0600
Re: assert expressions Wanderer <wanderer@dialup4less.com> - 2012-07-24 13:47 -0700
Re: assert expressions Wanderer <wanderer@dialup4less.com> - 2012-07-24 13:56 -0700
Re: assert expressions Wanderer <wanderer@dialup4less.com> - 2012-07-24 13:44 -0700
Re: assert expressions Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-24 15:22 -0600
Re: assert expressions Wanderer <wanderer@dialup4less.com> - 2012-07-24 14:25 -0700
csiph-web