How to write fast into a file in python?

88888 Dihedral dihedral88888 at googlemail.com
Sat May 18 07:09:58 EDT 2013


Steven D'Aprano於 2013年5月18日星期六UTC+8下午12時01分13秒寫道:
> On Fri, 17 May 2013 21:18:15 +0300, Carlos Nepomuceno wrote:
> 
> 
> 
> > I thought there would be a call to format method by "'%d\n' % i". It
> 
> > seems the % operator is a lot faster than format. I just stopped using
> 
> > it because I read it was going to be deprecated. :( Why replace such a
> 
> > great and fast operator by a slow method? I mean, why format is been
> 
> > preferred over %?
> 
> 
> 
> That is one of the most annoying, pernicious myths about Python, probably 
> 
> second only to "the GIL makes Python slow" (it actually makes it fast). 
> 
> 

The print function in python  is designed to print 
any printable object with a valid string representation.

The format part of the print function has to construct 
a printable string according to the format string 
and the variables passed in on the fly. 

If the acctual string to be printed in the format processing
is obtained in the high level OOP way , then it is definitely 
slow due to the high level overheads and generality requirements.








More information about the Python-list mailing list