Python object overhead?

Mark Nenadov mark at freelance-developer.com
Fri Mar 23 17:27:25 EDT 2007


On Fri, 23 Mar 2007 15:11:35 -0600, Matt Garman wrote:


> 
> Is this "just the way it is" or am I overlooking something obvious?
> 


Matt,

If you iterate over even the smallest object instantiation a large amount
of times, it will be costly compared to a simple list append.

I don't think you can get around some overhead with the objects.

However, in terms of generally efficiency not specifically related to
object instantiation, you should look into xreadlines().

I'd suggest doing the following instead of that while loop: 

for line in open(sys.argv[1]).xreadlines():
  ..


-- 
Mark Nenadov -> skype: marknenadov, web: http://www.marknenadov.com
-> "Glory is fleeting, but obscurity is forever." -- Napoleon Bonapart




More information about the Python-list mailing list