def __init__(self, file_path, mode, data_fmt, convert_type=None):
"""
Args:
file_path
mode: 'w', 'r', or 'a'. Automatically append 'b' to the mode.
data_fmt: see https://docs.python.org/2/library/struct.html
i - int; I - unsigned int; q - long long; Q - unsigned long long
f - float; d - double; s - string; c - char; ? - bool
b - signed char; B - unsigned char; h - short; H - unsigned short.
3i - tuple of 3 ints; 'ifb' - tuple of int, float, bool
convert_type: if you write int, file.read() will return a tuple (3,)
use convert_return to return convert_return(*read) instead.
"""
self.data_fmt = data_fmt
self._size = struct.calcsize(data_fmt)
self.convert_type = convert_type
mode = self._get_mode(mode)
AbstractFile.__init__(self, file_path, mode)
评论列表
文章目录