how to count lines in a file ?

Richard Jones rjones at ekit-inc.com
Thu Jul 25 17:46:00 EDT 2002


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 :(


    Richard





More information about the Python-list mailing list