[Python-Dev] Use for enumerate()

David Ascher DavidA@ActiveState.com
2002年4月26日 17:24:12 -0700


Patrick K. O'Brien wrote:
>[David Ascher]
>>>def getline(filename, lineno):
>> if lineno >= 1:
>> for i, line in enumerate(open(filename)):
>> if i == lineno - 1:
>> return line
>> return ''
>>>>But you broke the "always close the file" rule. Cheater!!! <wink>
>The file will get closed. I'm just not guaranteeing when =).

AltStyle によって変換されたページ (->オリジナル) /