Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 30 Apr 2015 21:42:25 -0500 Date: Thu, 30 Apr 2015 19:42:24 -0700 From: Larry Hudson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 Newsgroups: comp.lang.python Subject: Re: seek operation in python References: <8b2bd328-08a6-4211-85c4-8d117d1aae1e@googlegroups.com> <87vbge9lm6.fsf@Equus.decebal.nl> <87y4lavy4q.fsf@Equus.decebal.nl> <87r3r1s5ln.fsf@Equus.decebal.nl> In-Reply-To: <87r3r1s5ln.fsf@Equus.decebal.nl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 29 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-ern5nIxUNCqvmuHwnY9eUZnytFDcdoAJJo16e5iD7PnI1RKl8kCO54qg6lHNCAweVtGH9fOQ/B2zpEM!DAbUCxriF51EsvcmWqCeYnJOu1pkffs6zqs0d1XMMQfk9ozVWieE4O+JO9TwdTWhY2AKhBtS1Q== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2538 X-Received-Bytes: 2650 X-Received-Body-CRC: 3673849952 Xref: csiph.com comp.lang.python:89688 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 -=-