Sebastian Noack | 6 Oct 16:13

Fw: Creating a file-like object.

On Sun, 5 Oct 2008 00:10:22 -0400
"David Goodger" <goodger <at> python.org> wrote:

> On Mon, Sep 29, 2008 at 12:13, Sebastian Noack
> <sebastian.noack <at> googlemail.com> wrote:
> > by using publish_file, I can read text from a file-like object and
> > write it to another file-like object, but is there a way to get a
> > file-like object which formats the text while it gets read? Thanks.
> 
> I don't understand what you're asking for. Please explain further, and
> include examples of what you'd like (input & output, code samples,
> etc.).
> 

I was asking for a way to don't have to publish the complete file at
once. For example:

fd = publish_*(...)
while True:
    buffer = fd.read(512)
    if len(buffer) == 0: break
    sys.stdout.write(buffer)

Note that this is just an example, I know that i can write to
sys.stdout directly. But sometimes i need a file like object to pass it
to an other function which expects a file-like object. In this case i
could create a StringIO but this would be waste of memory and
performance. Thanks

Regards
(Continue reading)

David Goodger | 6 Oct 16:38
Favicon

Re: Fw: Creating a file-like object.

On Mon, Oct 6, 2008 at 10:14, Sebastian Noack
<sebastian.noack <at> googlemail.com> wrote:
> On Sun, 5 Oct 2008 00:10:22 -0400
> "David Goodger" <goodger <at> python.org> wrote:
>> On Mon, Sep 29, 2008 at 12:13, Sebastian Noack
>> <sebastian.noack <at> googlemail.com> wrote:
>> > by using publish_file, I can read text from a file-like object and
>> > write it to another file-like object, but is there a way to get a
>> > file-like object which formats the text while it gets read? Thanks.
>>
>> I don't understand what you're asking for. Please explain further, and
>> include examples of what you'd like (input & output, code samples,
>> etc.).
>
> I was asking for a way to don't have to publish the complete file at
> once. For example:
>
> fd = publish_*(...)
> while True:
>    buffer = fd.read(512)
>    if len(buffer) == 0: break
>    sys.stdout.write(buffer)
>
> Note that this is just an example, I know that i can write to
> sys.stdout directly. But sometimes i need a file like object to pass it
> to an other function which expects a file-like object. In this case i
> could create a StringIO but this would be waste of memory and
> performance. Thanks

I think I understand what you're asking now: you want lazy evaluation,
(Continue reading)


Gmane