On Mon, Aug 31, 2009 at 14:08, Laurent PETIT<laurent.pe...@gmail.com> wrote:
> Hi,
>
> Just one point:
>
> 2009/8/30 Dan Fichter <daniel.fich...@gmail.com>
>>
>> Read the contents of a file.
>>
>> [Clojure]
>>
>> (slurp filename)
>>
>> [Python]
>>
>> open(filename, 'r').read() # who cares about closing files opened in
>> read-mode?
>
> "who cares about closing files opened in read-mode" ?
>
> I would say anybody concerned about blowing up the underlying OS if not
> releasing files handles (especially if you open files in a tight loop), or
> do I miss something ?

CPython will close the underlying file when its handle is garbage
collection. The collection itself will be prompt and deterministic due
to CPython's use of reference counting for GC. You shouldn't have a
problem, even in a tight loop.

Jython, on the other hand, ... uses Java's GC, which has many
advantages of Python's 70's style reference counter, but being
deterministic isn't one of them.

Incidentally, Python 2.6 provides something akin to Clojure's with-open macro:

with open( "somefile", "rb" ) as aFile:
    do_something_with_contents_of(aFile)


// BEn

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to