RE: How to write fast into a file in python?

2013-05-20 Thread Carlos Nepomuceno
fast into a file in python? > > On 19/05/2013 04:53, Carlos Nepomuceno wrote: >> >>> Date: Sat, 18 May 2013 22:41:32 -0400 >>> From: da...@davea.name >>> To: python-list@python.org >>> Subject: Re: How to writ

Re: How to write fast into a file in python?

2013-05-19 Thread Tim Roberts
Carlos Nepomuceno wrote: >Python really writes '\n\r' on Windows. Just check the files. It actually writes \r\n, but it's not Python that's doing it. It's the C runtime library. And, of course, you can eliminate all of that by opening the file in binary mode open(name,'wb'). -- Tim Roberts, t

Re: How to write fast into a file in python?

2013-05-19 Thread MRAB
On 19/05/2013 04:53, Carlos Nepomuceno wrote: Date: Sat, 18 May 2013 22:41:32 -0400 From: da...@davea.name To: python-list@python.org Subject: Re: How to write fast into a file in python? On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote: Python really

RE: How to write fast into a file in python?

2013-05-19 Thread Carlos Nepomuceno
ooops! I meant to say Cython. nevermind... > Date: Sun, 19 May 2013 19:21:54 +1000 > Subject: Re: How to write fast into a file in python? > From: ros...@gmail.com > To: python-list@python.org > > On Sun, May 19, 2013 at 3:31 PM, Carlos N

Re: How to write fast into a file in python?

2013-05-19 Thread Chris Angelico
On Sun, May 19, 2013 at 3:31 PM, Carlos Nepomuceno wrote: > Thanks Dan! I've never used CPython or PyPy. Will try them later. CPython is the "classic" interpreter, written in C. It's the one you'll get from the obvious download links on python.org. ChrisA -- http://mail.python.org/mailman/listi

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
snepomuc...@outlook.com > To: python-list@python.org > Subject: RE: How to write fast into a file in python? > Date: Sun, 19 May 2013 08:31:08 +0300 > CC: lokeshkopp...@gmail.com > > Thanks Dan! I've never used CPython or PyPy. Will try them later. > > I t

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
.org/~dstromberg/UCI-license.html > Date: Sat, 18 May 2013 12:38:30 -0700 > Subject: Re: How to write fast into a file in python? > From: drsali...@gmail.com > To: lokeshkopp...@gmail.com > CC: python-list@python.org > > > With CPython 2.7.3: > ./t >

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
> Date: Sat, 18 May 2013 22:41:32 -0400 > From: da...@davea.name > To: python-list@python.org > Subject: Re: How to write fast into a file in python? > > On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote: >> Python really writes '

Re: How to write fast into a file in python?

2013-05-18 Thread Dave Angel
On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote: Python really writes '\n\r' on Windows. Just check the files. That's backwards. '\r\n' on Windows, IF you omit the b in the mode when creating the file. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list

Re: How to write fast into a file in python?

2013-05-18 Thread Steven D'Aprano
On Sat, 18 May 2013 15:14:31 -0400, Dennis Lee Bieber wrote: > tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos > declaimed the following in > gmane.comp.python.general: > > >> You mentioned "\n" translating to two lines, but this won't happen. >> Windows will not mess with what you write to y

Re: How to write fast into a file in python?

2013-05-18 Thread Fábio Santos
On 18 May 2013 20:19, "Dennis Lee Bieber" wrote: > > tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos > declaimed the following in > gmane.comp.python.general: > > > > You mentioned "\n" translating to two lines, but this won't happen. Windows > > will not mess with what you write to your file.

Re: How to write fast into a file in python?

2013-05-18 Thread Roy Smith
In article , Dennis Lee Bieber wrote: > tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos > declaimed the following in > gmane.comp.python.general: > > > > You mentioned "\n" translating to two lines, but this won't happen. Windows > > will not mess with what you write to your file. It's just

Re: How to write fast into a file in python?

2013-05-18 Thread Dan Stromberg
With CPython 2.7.3: ./t time taken to write a file of size 52428800 is 15.86 seconds time taken to write a file of size 52428800 is 7.91 seconds time taken to write a file of size 52428800 is 9.64 seconds With pypy-1.9: ./t time taken to write a file of size 52428800 is 3.708232 seconds

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
55 +0100 > Subject: RE: How to write fast into a file in python? > From: fabiosantos...@gmail.com > To: carlosnepomuc...@outlook.com > CC: python-list@python.org > > > On 17 May 2013 19:38, "Carlos Nepomuceno" > mailto:carlosnepomuc...@outlook.com>> &

Re: How to write fast into a file in python?

2013-05-18 Thread Chris Angelico
On Sat, May 18, 2013 at 5:49 PM, Fábio Santos wrote: > Putting len(os.linesep)'s value into a local variable will make accessing it > quite a bit faster. But why would you want to do that? > > You mentioned "\n" translating to two lines, but this won't happen. Windows > will not mess with what you

Re: How to write fast into a file in python?

2013-05-18 Thread 88888 Dihedral
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 i

RE: How to write fast into a file in python?

2013-05-18 Thread Fábio Santos
On 17 May 2013 19:38, "Carlos Nepomuceno" wrote: > > Think the following update will make the code more portable: > > x += len(line)+len(os.linesep)-1 > > Not sure if it's the fastest way to achieve that. :/ > Putting len(os.linesep)'s value into a local variable will make accessing it quite a bi

Re: How to write fast into a file in python?

2013-05-17 Thread Chris Angelico
On Sat, May 18, 2013 at 2:01 PM, Steven D'Aprano wrote: > Consider if x is an arbitrary object, and you call "%s" % x: > > py> "%s" % 23 # works > '23' > py> "%s" % [23, 42] # works > '[23, 42]' > > and so on for *almost* any object. But if x is a tuple, strange things > happen Which can be gua

Re: How to write fast into a file in python?

2013-05-17 Thread Steven D'Aprano
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 ope

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
Think the following update will make the code more portable: x += len(line)+len(os.linesep)-1 Not sure if it's the fastest way to achieve that. :/ > On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote: > >> ### fastwrite5.py ### >> import cStringIO >> size = 50*1024*1024 >> value = 0 >>

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
You've hit the bullseye! ;) Thanks a lot!!! > Oh, I forgot to mention: you have a bug in this function. You're already > including the newline in the len(line), so there is no need to add one. > The result is that you only generate 44MB instead of 50MB. That's because I'm running on Windows. Wha

Re: How to write fast into a file in python?

2013-05-17 Thread Steven D'Aprano
On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote: > ### fastwrite5.py ### > import cStringIO > size = 50*1024*1024 > value = 0 > filename = 'fastwrite5.dat' > x = 0 > b = cStringIO.StringIO() > while x < size: >     line = '{0}\n'.format(value) >     b.write(line) >     value += 1 >    

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
  line = '{0}\n'.format(value)     b.write(line)     value += 1     x += len(line)+1     f = open(filename, 'w')     f.write(b.getvalue())     f.close()     b.close() if __name__ == '__main__':     run() ---------------- > From: steve+c

Re: How to write fast into a file in python?

2013-05-17 Thread Steven D'Aprano
On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote: > I've got the following results on my desktop PC (Win7/Python2.7.5): > > C:\src\Python>python -m timeit -cvn3 -r3 "execfile('fastwrite2.py')" raw > times: 123 126 125 > 3 loops, best of 3: 41 sec per loop Your times here are increased

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
.dat' shutil.copyfile(src, dst) -------- > Date: Fri, 17 May 2013 07:58:43 -0400 > From: da...@davea.name > To: python-list@python.org > Subject: Re: How to write fast into a file in python? > > On 05/17/2013 12:35 AM, lokeshkopp...@gmail.com wrot

Re: How to write fast into a file in python?

2013-05-17 Thread Dave Angel
On 05/17/2013 12:35 AM, lokeshkopp...@gmail.com wrote: On Friday, May 17, 2013 8:50:26 AM UTC+5:30, lokesh...@gmail.com wrote: I need to write numbers into a file upto 50mb and it should be fast can any one help me how to do that? i had written the following code.. value = 0 with open(file

Re: How to write fast into a file in python?

2013-05-16 Thread lokeshkoppaka
On Friday, May 17, 2013 8:50:26 AM UTC+5:30, lokesh...@gmail.com wrote: > I need to write numbers into a file upto 50mb and it should be fast > > can any one help me how to do that? > > i had written the following code.. > > ---

Re: How to write fast into a file in python?

2013-05-16 Thread Steven D'Aprano
On Thu, 16 May 2013 20:20:26 -0700, lokeshkoppaka wrote: > I need to write numbers into a file upto 50mb and it should be fast can > any one help me how to do that? > i had written the following code.. > -- > def create_file_numbe