how to count lines in a file ?

Gerhard Häring gerhard.haering at gmx.de
Wed Jul 24 18:46:24 EDT 2002


* Delaney, Timothy <tdelaney at avaya.com> [2002-07-25 08:31 +1000]:
> > From: Bo M. Maryniuck [mailto:b.maryniuk at forbis.lt]
> > 
> > print len(open('/etc/passwd').readlines())
> 
> There is currently discussion on python-dev of the file object possibly
> becoming collectable by GC (and hence not going away immediately the last
> reference you know about disappears).

:-/

I thought that Python had a reference-counting garbage collector
combined with a mark-and-sweep gc?! So that if a refcount goes to zero,
I can count on the object being collected immediately?

If this is not true, then some of my own code is buggy, too :-(

(I didn't target Jython up to now, where the gc works differently due to
the JVM)

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list