Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89611
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '"""': 0.07; 'suppose': 0.07; 'exception.': 0.09; 'subject:None': 0.09; 'way:': 0.09; 'python': 0.11; 'def': 0.12; 'big,': 0.16; 'fetch': 0.16; 'subject:exception': 0.16; 'exception': 0.16; 'index': 0.16; 'wrote:': 0.18; 'file,': 0.19; "skip:' 30": 0.19; 'header:User- Agent:1': 0.23; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'skip:g 30': 0.30; 'code': 0.31; 'catching': 0.31; 'file:': 0.31; 'ok.': 0.31; 'problem.': 0.35; 'returning': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:o 30': 0.61; 'first': 0.61; 'more': 0.64; 'fire': 0.65; 'charset:windows-1252': 0.65; 'received:74.208': 0.68; 'received:74.208.4.194': 0.84; 'subject:Let': 0.91 |
| Date | Thu, 30 Apr 2015 04:18:06 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Let exception fire or return None |
| References | <87bni6awol.fsf@Equus.decebal.nl> |
| In-Reply-To | <87bni6awol.fsf@Equus.decebal.nl> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V03:K0:dIg6u2DuSykoT3/A7nD7dYDSdnlv0OQLbzAgOzWnnu8FVpiciXw dkomVdcxrvXP0dpzR1NpZQsfYTh0DQfkIq736yTUKKdz7j7xJPwJdwrm/H75vpy2VSkTl1T vmX/9P+G9c5MlF/GmcNces1EHwxpG45lex0AzzWgBd+EHuZzIbwouBEPAtwfK61ccTQzeZ/ lDxISMS7ID0JTItB/BFtw== |
| X-UI-Out-Filterresults | notjunk:1; |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.119.1430381898.3680.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430381898 news.xs4all.nl 2846 [2001:888:2000:d::a6]:49786 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89611 |
Show key headers only | View raw
On 04/30/2015 03:43 AM, Cecil Westerhof wrote: > I have a function to fetch a message from a file: > def get_indexed_message(message_filename, index): > """ > Get index message from a file, where 0 gets the first message > """ > > return open(expanduser(message_filename), 'r').readlines()[index].rstrip() > > What is more the Python way: let the exception fire like this code > when index is to big, or catching it and returning None? > > I suppose working zero based is OK. > Fire an exception. One advantage is that the exception will pinpoint exactly which line of the function had a problem. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Let exception fire or return None Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 09:43 +0200
Re: Let exception fire or return None Dave Angel <davea@davea.name> - 2015-04-30 04:18 -0400
Re: Let exception fire or return None Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 11:13 +0200
Re: Let exception fire or return None Peter Otten <__peter__@web.de> - 2015-04-30 11:30 +0200
Re: Let exception fire or return None Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 13:26 +0200
Re: Let exception fire or return None Peter Otten <__peter__@web.de> - 2015-04-30 14:28 +0200
Re: Let exception fire or return None Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 16:53 +0200
Re: Let exception fire or return None Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 14:22 +0200
Re: Let exception fire or return None Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-30 14:05 +0200
Re: Let exception fire or return None Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-04-30 14:30 +0200
csiph-web