<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif"><div class="gmail_default">The struct unpack API is inconvenient to use with files. I must do:</div><div class="gmail_default"><br></div><div class="gmail_default">struct.unpack(fmt, file.read(struct.calcsize(fmt))</div><div class="gmail_default"><br></div><div class="gmail_default">every time I want to read a struct from the file. I ended up having to create a utility function for this due to how frequently I was using struct.unpack with files:</div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default">def unpackStruct(fmt, frm):</div><div class="gmail_default"> if isinstance(frm, io.IOBase):</div><div class="gmail_default"> return struct.unpack(fmt, frm.read(struct.calcsize(fmt)))</div><div class="gmail_default"> else:</div><div class="gmail_default"> return struct.unpack(fmt, frm)</div><div><br></div><div>This seems like something that should be built into the default implementation -- struct.unpack already has all the information it needs with just the struct format and open binary file. Current behavior is an error since struct.unpack only supports bytes-like objects, so this should be backwards compatible except in the case where a developer is relying on that to error in a try block instead of verifying the buffer type beforehand.</div></div></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
</blockquote></div></div>