Real Problems with Python

Bjorn Pettersen bpetterson at uswest.net
Mon Feb 14 18:10:06 CET 2000


But if we get coroutines a la Stackless Python, we could do something like:

    def readline(name):
        fp = open(name)
        while 1:
            line = fp.readline()
            if not line: break
            suspend line
        fp.close()

(someone please correct my semantics if I'm wrong -- I really haven't played enough
with suspend yet :-)

of-course-you-can-do-the-same-thing-with-continuations<wink>'ly y'rs
-- bjorn

Martin von Loewis wrote:

> François Pinard <pinard at iro.umontreal.ca> writes:
>
> > I'm not sure of the implications of the above, but one sure thing is that I
> > very much like the current implications of reference counting.  When I write:
> >
> >     for line in open(FILE).readlines():
> >
> > I rely on the fact FILE will automatically get closed, and very soon since
> > no other references remain.  I could of course use another Python line for
> > opening FILE, and yet another for explicitely closing it, as I was doing
> > in my first Python days, but I learned to like terse writings like above,
> > and I do not think there is any loss in legibility in this terseness.
>
> Indeed. I think Tim's right here (as always:); if the request for
> garbage collection is rephrased as 'reclaim cycles', everybody will be
> happy.
>
> Regards,
> Martin




More information about the Python-list mailing list