Re: [Tutor] creating a buffer object from a file ?

2007-05-31 Thread Alan Gauld

"Jerry Hill" <[EMAIL PROTECTED]> wrote

>> I think this got lost among the threads:
>
> I think it got lost because you haven't given us enough information 
> to
> answer your question.
>
>> in reality what is a buffer object used for ? reading
>> a file itself creates a string as in itself,
>
> We don't know.  Your original email said you needed a buffer object,

The problem is that the Python docs refer to "a buffer object"
but are not very forthcoming about exactly what it is or when/why
you should use one. I confess that until Iyer asked his question
I didn't even know they existed and still don't know when or
why I'd need one.

They appear to be some kind of string based object used in
the internals of Python but with some operations blocked.
But the only halfway useful info is what you get when you
do help(buffer).

Sorry Iyer, I can't really tell you anymore than I did already.

As Jerry says, maybe if  you could remind us of the context
where you were told you needed to use a buffer object? I've never
seen such a demand in Python myself.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a buffer object from a file ?

2007-05-31 Thread Jerry Hill
On 5/31/07, Iyer <[EMAIL PROTECTED]> wrote:
> I think this got lost among the threads:

I think it got lost because you haven't given us enough information to
answer your question.

> in reality what is a buffer object used for ? reading
> a file itself creates a string as in itself,

We don't know.  Your original email said you needed a buffer object,
but didn't tell us why.  As a consequence, the only one who knows why
you need one is you.  Perhaps if you actually showed us some code, or
mentioned what library you were using that required a buffer object?

-- 
Jerry
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a buffer object from a file ?

2007-05-31 Thread Iyer
I think this got lost among the threads:


in reality what is a buffer object used for ? reading
a file itself creates a string as in itself, 

file_handle = file ("path_to_file")

file_data = file_handle.read()

# file_data is a string, so why is a buffer object is
needed ?

the data in the binary file is just raw binary. 

I apologize for replying to the existing subject.
Thanks for letting me know. I shall make sure this
doesn't happen again.

thanks
iyer

--- Alan Gauld <[EMAIL PROTECTED]> wrote:

> "Iyer" <[EMAIL PROTECTED]> wrote
> 
> > How do I go about creating a buffer object from
> > a file containing binary data ? I have a function
> > that accepts only buffer objects for it's
> parameters
> 
> Can you define what you mean by a buffer object?
> Python uses duck typing so, unless the function has
> been badly coded with an explicit type check, it
> should accept any object that supports the methods
> used.
> 
> If you really do need a buffer the docs say:
> 
> -
> Buffer objects are not directly supported by Python
> syntax, but can be created by calling the builtin
> function buffer(). They don't support concatenation
> or repetition.
> -
> 
> Which was new to me. But some experimentation
> with the interpreter shows:
> 
> class buffer(object)
>  |  buffer(object [, offset[, size]])
>  |
>  |  Create a new buffer object which references the
> given object.
>  |  The buffer will reference a slice of the target
> object from the
>  |  start of the object (or at the specified
> offset). The slice will
>  |  extend to the end of the target object (or with
> the specified 
> size).
> ---
> and
> 
> >>> b = buffer('fredrica', 2,4)
> >>> b[:]
> 'edri'
> 
> 
> So we can see how to create a buffer object.
> You want to do it with a binary file. You can read
> the content
> of a binary file using the struct module. But you
> need to know
> what kind of data is in your file. To create a
> buffer you need
> a string. So do you want your buffer to process the
> raw binary
> bytes as if they were a string? Or do you want to
> convert the
> binary data and then convert it again into a string
> representation?
> 
> Either is possible but you need to decide which you
> need.
> 
> BTW Please don't post new subjects to the list by
> replying
> to an existing subject. For those using threaded
> readers it
> buries your post insife another thread, in this case
> 3 levels
> deep in one about MSSQL! I only just noticed it. Its
> better
> to start a fresh message. After all its not exactly 
> difficult to
> type tutor@python.org in the to line! :-)
> 
> HTH,
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


 

No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] creating a buffer object from a file ?

2007-05-25 Thread Iyer
I think this got lost among the threads:


thanks, alan for your helpful response. 

in reality what is a buffer object used for ? reading
a file itself creates a string as in itself, 

file_handle = file ("path_to_file")

file_data = file_handle.read()

# file_data is a string, so why is a buffer object is
needed ?

the data in the binary file is just raw binary. 

I apologize for replying to the existing subject.
Thanks for letting me know. I shall make sure this
doesn't happen again.

thanks
iyer

--- Alan Gauld <[EMAIL PROTECTED]> wrote:

> "Iyer" <[EMAIL PROTECTED]> wrote
> 
> > How do I go about creating a buffer object from
> > a file containing binary data ? I have a function
> > that accepts only buffer objects for it's
> parameters
> 
> Can you define what you mean by a buffer object?
> Python uses duck typing so, unless the function has
> been badly coded with an explicit type check, it
> should accept any object that supports the methods
> used.
> 
> If you really do need a buffer the docs say:
> 
> -
> Buffer objects are not directly supported by Python
> syntax, but can be created by calling the builtin
> function buffer(). They don't support concatenation
> or repetition.
> -
> 
> Which was new to me. But some experimentation
> with the interpreter shows:
> 
> class buffer(object)
>  |  buffer(object [, offset[, size]])
>  |
>  |  Create a new buffer object which references the
> given object.
>  |  The buffer will reference a slice of the target
> object from the
>  |  start of the object (or at the specified
> offset). The slice will
>  |  extend to the end of the target object (or with
> the specified 
> size).
> ---
> and
> 
> >>> b = buffer('fredrica', 2,4)
> >>> b[:]
> 'edri'
> 
> 
> So we can see how to create a buffer object.
> You want to do it with a binary file. You can read
> the content
> of a binary file using the struct module. But you
> need to know
> what kind of data is in your file. To create a
> buffer you need
> a string. So do you want your buffer to process the
> raw binary
> bytes as if they were a string? Or do you want to
> convert the
> binary data and then convert it again into a string
> representation?
> 
> Either is possible but you need to decide which you
> need.
> 
> BTW Please don't post new subjects to the list by
> replying
> to an existing subject. For those using threaded
> readers it
> buries your post insife another thread, in this case
> 3 levels
> deep in one about MSSQL! I only just noticed it. Its
> better
> to start a fresh message. After all its not exactly 
> difficult to
> type tutor@python.org in the to line! :-)
> 
> HTH,
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



   



 

Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a buffer object from a file ?

2007-05-23 Thread Iyer
thanks, alan for your helpful response. 

in reality what is a buffer object used for ? reading
a file itself creates a string as in itself, 

file_handle = file ("path_to_file")

file_data = file_handle.read()

# file_data is a string, so why is a buffer object is
needed ?

the data in the binary file is just raw binary. 

I apologize for replying to the existing subject.
Thanks for letting me know. I shall make sure this
doesn't happen again.

thanks
iyer

--- Alan Gauld <[EMAIL PROTECTED]> wrote:

> "Iyer" <[EMAIL PROTECTED]> wrote
> 
> > How do I go about creating a buffer object from
> > a file containing binary data ? I have a function
> > that accepts only buffer objects for it's
> parameters
> 
> Can you define what you mean by a buffer object?
> Python uses duck typing so, unless the function has
> been badly coded with an explicit type check, it
> should accept any object that supports the methods
> used.
> 
> If you really do need a buffer the docs say:
> 
> -
> Buffer objects are not directly supported by Python
> syntax, but can be created by calling the builtin
> function buffer(). They don't support concatenation
> or repetition.
> -
> 
> Which was new to me. But some experimentation
> with the interpreter shows:
> 
> class buffer(object)
>  |  buffer(object [, offset[, size]])
>  |
>  |  Create a new buffer object which references the
> given object.
>  |  The buffer will reference a slice of the target
> object from the
>  |  start of the object (or at the specified
> offset). The slice will
>  |  extend to the end of the target object (or with
> the specified 
> size).
> ---
> and
> 
> >>> b = buffer('fredrica', 2,4)
> >>> b[:]
> 'edri'
> 
> 
> So we can see how to create a buffer object.
> You want to do it with a binary file. You can read
> the content
> of a binary file using the struct module. But you
> need to know
> what kind of data is in your file. To create a
> buffer you need
> a string. So do you want your buffer to process the
> raw binary
> bytes as if they were a string? Or do you want to
> convert the
> binary data and then convert it again into a string
> representation?
> 
> Either is possible but you need to decide which you
> need.
> 
> BTW Please don't post new subjects to the list by
> replying
> to an existing subject. For those using threaded
> readers it
> buries your post insife another thread, in this case
> 3 levels
> deep in one about MSSQL! I only just noticed it. Its
> better
> to start a fresh message. After all its not exactly 
> difficult to
> type tutor@python.org in the to line! :-)
> 
> HTH,
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



   
Luggage?
 GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a buffer object from a file ?

2007-05-22 Thread Alan Gauld
"Iyer" <[EMAIL PROTECTED]> wrote

> How do I go about creating a buffer object from
> a file containing binary data ? I have a function
> that accepts only buffer objects for it's parameters

Can you define what you mean by a buffer object?
Python uses duck typing so, unless the function has
been badly coded with an explicit type check, it
should accept any object that supports the methods
used.

If you really do need a buffer the docs say:

-
Buffer objects are not directly supported by Python
syntax, but can be created by calling the builtin
function buffer(). They don't support concatenation
or repetition.
-

Which was new to me. But some experimentation
with the interpreter shows:

class buffer(object)
 |  buffer(object [, offset[, size]])
 |
 |  Create a new buffer object which references the given object.
 |  The buffer will reference a slice of the target object from the
 |  start of the object (or at the specified offset). The slice will
 |  extend to the end of the target object (or with the specified 
size).
---
and

>>> b = buffer('fredrica', 2,4)
>>> b[:]
'edri'


So we can see how to create a buffer object.
You want to do it with a binary file. You can read the content
of a binary file using the struct module. But you need to know
what kind of data is in your file. To create a buffer you need
a string. So do you want your buffer to process the raw binary
bytes as if they were a string? Or do you want to convert the
binary data and then convert it again into a string representation?

Either is possible but you need to decide which you need.

BTW Please don't post new subjects to the list by replying
to an existing subject. For those using threaded readers it
buries your post insife another thread, in this case 3 levels
deep in one about MSSQL! I only just noticed it. Its better
to start a fresh message. After all its not exactly  difficult to
type tutor@python.org in the to line! :-)

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] creating a buffer object from a file ?

2007-05-21 Thread Iyer
How do I go about creating a buffer object from a file containing binary data ? 
I have a function that accepts only buffer objects for it's parameters and 
would like to pass on the contents of a file to that function. 
 
 thanks,
 iyer
 
   
-
You snooze, you lose. Get messages ASAP with AutoCheck
 in the all-new Yahoo! Mail Beta. ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor