Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100448
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Newsgroups | comp.lang.python |
| Subject | Re: Try: rather than if : |
| Date | Tue, 15 Dec 2015 17:16:31 +1100 |
| Lines | 21 |
| Message-ID | <mailman.12.1450160195.22044.python-list@python.org> (permalink) |
| References | <20151215061119.GA14163@cskk.homeip.net> |
| Reply-To | python-list@python.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.uni-berlin.de xkm8+xol+SL5NKT93f9yqAofrJfnDxOz6ZYGS8Oad/6g== |
| Return-Path | <cameron@cskk.homeip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'cc:addr:python-list': 0.09; '%s\\n"': 0.09; 'name)': 0.09; 'name):': 0.09; '>on': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'handle,': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'issue.': 0.20; 'cheers,': 0.22; 'this:': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'code': 0.30; 'handle': 0.34; 'i.e.': 0.35; 'subject:: ': 0.37; 'received:localdomain': 0.38; 'your': 0.60; 'cameron': 0.66; 'intent': 0.66; 'header :Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'reply- to:addr:python.org': 0.84 |
| Content-Disposition | inline |
| In-Reply-To | <20151215061119.GA14163@cskk.homeip.net> |
| User-Agent | Mutt/1.5.23 (2014-03-12) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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:100448 |
Show key headers only | View raw
On 15Dec2015 17:11, Cameron Simpson <cs@zip.com.au> wrote:
>On 14Dec2015 16:48, Vincent Davis <vincent@vincentdavis.net> wrote:
[...]
>>I think the intent of the original code was to check if handle had the
>>attribute "name", I don't think the attribute "write" was the issue.
[...]
>Secondly, for your use case "print the name if it has one" I _would_ use
>hasattr:
>
> if hasattr(handle, name):
> write("# Report_file: %s\n" % name)
On reflection, there's also this:
name = getattr(handle, 'name', repr(handle))
write("# Report_file: %s\n" % name)
i.e. _always_ identfy the handle, even if it has no nice name.
Cheers,
Cameron Simpson <cs@zip.com.au>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Try: rather than if : Cameron Simpson <cs@zip.com.au> - 2015-12-15 17:16 +1100
csiph-web