Re: Creating file of size x



On 2005-06-06, Jan Danielsson <jan.danielsson@xxxxxxxxx> wrote:

>>>The problem is that the design I'm working on won't guarantee
>>>what order the blocks will be returned in -- so I need to be
>>>able to seek to block n's location and write the ckeck block.
>>
>> Exactly. And precisely how did that fail?
>
> It didn't -- but that's on my platform;

What sort of programmer are you? If it works on your computer,
it's done, ship it! ;)

> I have no idea how it'll work on another platform; which is
> why I wanted to be able to first create the file of the
> specified size, and then start writing to it.
>
>>>Next block could be m, where m < n. So, they aren't continous.
>>
>> If you do a seek before each write, it doesn't matter.
>
> According to Python, posix, Linux, Windows, ANSI-C?

Good question. The Python documentation for the file object's
seek method is mute on the the topic of seeking past EOF. I
believe the observed behavior is required by POSIX, SVr4, and
BSD for lseek() (which, I presume, is what Python calls on
those platforms). That should have you covered for all of the
Linux and Linux-like OSes (included Mac OS X).

Under Win32, I don't know if there's an lseek() or what it
does.

I would guess that whoever wrote the file object's seek()
method went to some effort to make sure it works the same on
all platforms.

As somebody else pointed out, the following should work:

f = file('name','wb')
f.write('\x00' * requiredFileLength)

Then just do f.seek()/f.write() as the blocks come in.

--
Grant Edwards grante Yow! Sometime in 1993
at NANCY SINATRA will lead a
visi.com BLOODLESS COUP on GUAM!!
.



Relevant Pages

  • ANN: wxPython 2.6.2.1
    ... There have been many enhancements ... wxPython is a GUI toolkit for the Python programming language. ... Currently supported platforms are 32-bit Microsoft Windows, ...
    (comp.lang.python)
  • ANN: wxPython 2.6.2.1
    ... There have been many enhancements ... wxPython is a GUI toolkit for the Python programming language. ... Currently supported platforms are 32-bit Microsoft Windows, ...
    (comp.lang.python.announce)
  • Re: Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?
    ... >> Note that support for 754 was rare on Python platforms at the ... > production and handling of infinities and NaNs) for more than ...
    (comp.lang.python)
  • ANN: eGenix mx Base Package 2.0.6 (mxDateTime, mxTextTools, etc.)
    ... professional quality software tools which enhance Python's usability ... Windows and then run them on Unix platforms without change due to the ... * About Python: ... The new version includes patches needed to compile the package ...
    (comp.lang.python)
  • Re: [PATCH] kconfig: detect if -lintl is needed when linking conf,mconf
    ... several platforms, ld tries to lseek in the output file, and fails if it ... Ouch, indeed. ... I'd be interested in details on which platforms perform so lamely. ... I grep for lseek and its variants in the bfd and ld source code, ...
    (Linux-Kernel)