seek operation in python

Cecil Westerhof Cecil at decebal.nl
Thu Apr 30 16:50:44 EDT 2015


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.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list