File to dict
Duncan Booth
duncan.booth at invalid.invalid
Fri Dec 7 10:24:05 EST 2007
Neil Cerutti <horpner at yahoo.com> wrote:
> On 2007-12-07, Duncan Booth <duncan.booth at invalid.invalid> wrote:
>> from __future__ import with_statement
>>
>> def loaddomainowners(domain):
>> with open('/etc/virtual/domainowners','r') as infile:
>
> I've been thinking I have to use contextlib.closing for
> auto-closing files. Is that not so?
>
That is not so.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import with_statement
>>> with open('diffs.txt') as f:
... print len(list(f))
...
40
>>> f
<closed file 'diffs.txt', mode 'r' at 0x00AA0698>
>>>
More information about the Python-list
mailing list