def write_value(fd, fmt, *value, **kwargs):
"""
Write a single binary value to a file-like object.
Parameters
----------
fd : file-like object
Must be opened for writing, in binary mode.
fmt : str
A `struct` module `format character
<https://docs.python.org/2/library/struct.html#format-characters>`__
string.
value : any
The value to encode and write to the file.
endian : str
The endianness. Must be ``>`` or ``<``. Default: ``>``.
"""
endian = kwargs.get('endian', '>')
fmt = endian + fmt
fd.write(struct.pack(fmt, *value))
评论列表
文章目录