how to count lines in a file ?

Steve Holden sholden at holdenweb.com
Fri Jul 26 09:45:32 EDT 2002


"Richard Jones" <rjones at ekit-inc.com> wrote in message
news:mailman.1027633713.1308.python-list at python.org...
> On Fri, 26 Jul 2002 12:45 am, Alex Martelli wrote:
> > Michele Simionato wrote:
> > > Can somebody provide a simple example where the idiom
> > >
> > > file(name,'w').write(something)
> > >
> > > fails, in the sense that the file is not closed or something is not
> > > written ? I tried to hang the program with a memory overload
> >
> > [alex at lancelot jython-2.1]$ jython
> > Jython 2.1 on java1.4.0_01 (JIT: null)
> > Type "copyright", "credits" or "license" for more information.
> >
> > >> open('aname','w').write('something\n')
> >
> > [alex at lancelot jython-2.1]$ cat aname
> > [alex at lancelot jython-2.1]$ ll aname
> > -rw-rw-r--    1 alex     alex            0 Jul 25 16:41 aname
> > [alex at lancelot jython-2.1]$
> >
> > I exited the interactive interpreter with a clean, normal
> > control-D, but as you see file aname was created but its
> > contents not written.
> >
> > Any implementation of Python is perfectly free to choose
> > this behavior if it provides some other advantage.
>
> I think the major problem that we're running into here is that before
there
> was GC, the refcounting-based cleanup of objects was clear,
straight-forward
> and reliable. Now it's not clear when objects are cleared up. That's a
fairly
> major problem for some of us old-timers (and, quite possibly, a lot of
> newbies) to come to terms with. I hadn't realised that GC threw such a
big,
> ugly spanner in the works :(
>

The "ugly spanner" thrown by GC is simply the ability to collect cyclic
garbage. By definition, in prior implementations of CPython, such garbage
was never collected (and therefore the __del__() method was never called on
objects in cycles) because the refcount never went down to zero.

So what you appear to dislike is that there is now a *chance* that __del__()
will be called on cyclic garbage, when there wasn't before.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list