def get_size(variable):
'''Get bytes of variable
'''
if type(variable).__module__ == np.__name__:
variable = variable.tobytes()
elif type(variable) is str:
assert (all(ord(c) < 256) for c in variable)
else:
raise ValueError('Data type not supported')
# checking the length of a bytestring is more accurate
return len(variable)
评论列表
文章目录