write a 20GB file

J dreadpiratejeff at gmail.com
Fri May 14 10:50:49 EDT 2010


On Fri, May 14, 2010 at 07:32, Jackie Lee <jackie.space at gmail.com> wrote:
> Thx, Dave,
>
> The code works fine. I just don't know how f.write works. It says that
> file.write won't write the file until file.close or file.flush. So I
> don't know if the following one is more efficient (sorry I forget to
> add condition to break the loop):

someone smarter than me can correct me, but file.write() will write
when it's buffer is filled, or close() or flush() are called.
I don't know what the default buffer size for file.write() is though.
close() flushes the buffer before closing the file, and flush()
flushes the buffer and leaves the file open for further writing.

> try:
>        f=open(sys.argv[1],'rb+')
> except (IOError,Exception):
>    print '''usage:
>        scriptname segyfilename
> '''

You can just add a f.flush() every time you write to the file, but, I
tend to open files with 0 buffer size like this:

f = open(filename,"rb+",0)

Then again, I don't deal with files of that size, so there could be a
problem with my way once you start scaling up to the 20GB or larger
that you're working with.

Again, I could be wrong about all of that, so if so, I hope someone
will correct me and fix my understanding...

Cheers,

Jeff



More information about the Python-list mailing list