Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89688
| Date | 2015-04-30 19:42 -0700 |
|---|---|
| From | Larry Hudson <orgnut@yahoo.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: seek operation in python |
| References | (2 earlier) <87vbge9lm6.fsf@Equus.decebal.nl> <mailman.118.1430379207.3680.python-list@python.org> <87y4lavy4q.fsf@Equus.decebal.nl> <CJydnT_05MIuGd_InZ2dnUU7-UGdnZ2d@giganews.com> <87r3r1s5ln.fsf@Equus.decebal.nl> |
| Message-ID | <TM2dnd-1zveMdd_InZ2dnUU7-eednZ2d@giganews.com> (permalink) |
On 04/30/2015 01:50 PM, Cecil Westerhof wrote:
> Op Thursday 30 Apr 2015 21:38 CEST schreef Larry Hudson:
>
>> On 04/30/2015 01:06 AM, Cecil Westerhof wrote:
>> [snip]
>>
>>> I wrote a module where I have:
>>> 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()
>>>
>> Very minor nit unrelated to the file closing question:
>> This would be a good place to give index a default value...
>>
>> def get_indexed_message(message_filename, index=0):
>
> Why would you want this? I think the index should always be defined.
>
Matter of opinion, of course, but this allows calling the function without specifying the index
and you still get a useful (and logical) result. I find this convenient in most similar cases.
Using default parameters is quite Pythonic. Note that this _permits_ using the function this
way, it does not _require_ it. Of course, it also should be suitably documented. Naturally, YMMV.
-=- Larry -=-
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
seek operation in python siva sankari R <buddingrose11@gmail.com> - 2015-04-29 11:08 -0700
Re: seek operation in python Joel Goldstick <joel.goldstick@gmail.com> - 2015-04-29 14:17 -0400
Re: seek operation in python siva sankari R <buddingrose11@gmail.com> - 2015-04-29 11:26 -0700
Re: seek operation in python Billy Earney <billy.earney@gmail.com> - 2015-04-29 13:42 -0500
Re: seek operation in python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 21:53 +0100
Re: seek operation in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 10:19 +1000
Re: seek operation in python MRAB <python@mrabarnett.plus.com> - 2015-04-29 19:50 +0100
Re: seek operation in python John Gordon <gordon@panix.com> - 2015-04-29 18:53 +0000
Re: seek operation in python Chris Angelico <rosuav@gmail.com> - 2015-04-30 10:33 +1000
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 08:27 +0200
Re: seek operation in python Chris Angelico <rosuav@gmail.com> - 2015-04-30 17:33 +1000
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 10:06 +0200
Re: seek operation in python Dave Angel <davea@davea.name> - 2015-04-30 04:31 -0400
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 11:06 +0200
Re: seek operation in python Chris Angelico <rosuav@gmail.com> - 2015-04-30 19:39 +1000
Re: seek operation in python Larry Hudson <orgnut@yahoo.com> - 2015-04-30 12:38 -0700
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 22:50 +0200
Re: seek operation in python Larry Hudson <orgnut@yahoo.com> - 2015-04-30 19:42 -0700
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 14:31 +0200
csiph-web