how to count lines in a file ?

Jonathan Hogg jonathan at onegoodidea.com
Thu Jul 25 07:27:16 EDT 2002


On 25/7/2002 9:24, in article
mailman.1027585535.11720.python-list at python.org, "Bo M. Maryniuck"
<b.maryniuk at forbis.lt> wrote:

> Umm... Richard, I just've played over all we talking about in not best way,
> but in anyway I'm little hooked and I would like to know what's _exactly_
> going on:
> 
> *bo at spectator:(~) python
> Python 2.2 (#1, Dec 23 2001, 09:30:32)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import gc
>>>> len(gc.get_objects())
> 844
>>>> a = open('/etc/passwd')
>>>> len(gc.get_objects())
> 844
>>>> del a
>>>> len(gc.get_objects())
> 844
>>>> #Huh?

As noted earlier in the thread, files don't take part in gc. This is because
they don't (at least for the moment) hold references to other objects.
Generally only container objects (lists, dictionaries, tuples, instances,
classes, etc.) take part in gc and show up in the gc statistics.

-reference-counting-is-good-enough-for-some-<wing>-ly y'rs,

Jonathan




More information about the Python-list mailing list