> Actually I would like code like
>   s = socket()
>   ...
>   header = struct.unpack("i", s)
> 
> In other words, struct should interact with files/streams directly, instead 
> of 
> requiring me to first read a chunk who's size I manually have to determine 
> etc.

That is easy to achieve using the existing API:

def read_and_unpack(stream, format):
    data = stream.read(struct.calcsize(format))
    return struct.unpack(format, data)

> Otherwise, I'm +1 on your suggestion, avoiding copying is a good thing.

I believe my function also doesn't involve any unnecessary copies.

Regards,
Martin
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to