Python object overhead?

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Fri Mar 23 20:36:22 EDT 2007


Matt Garman wrote:

> Since each line corresponds to a record, what I'm trying to do is
> create an object from each record.  However, it seems that doing
> this causes the memory overhead to go up two or three times.

(Note that almost everything in Python is an object!)

> Example 1: read lines into list:
> # begin readlines.py
> import sys, time
> filedata = list()
> file = open(sys.argv[1])
> while True:
>     line = file.readline()
>     if len(line) == 0: break # EOF

"one blank line" == "EOF"? That's strange. Intended?

The most common form for this would be "if not line: (do
something)".

> Example 2: read lines into objects:
> # begin readobjects.py
> import sys, time
> class FileRecord:
>     def __init__(self, line):
>         self.line = line

What's this class intended to do?

Regards,


Björn

-- 
BOFH excuse #1:

clock speed




More information about the Python-list mailing list