@author jackzhenguo @desc @date 2019/5/3
def str_byte_len(mystr): return (len(mystr.encode('utf-8')))
测试:
str_byte_len('i love python') # 13(个字节) str_byte_len('字符') # 6(个字节)