繁体   English   中英

有没有将 python 字节转换为字符串并返回的好方法?

[英]is there a good way to convert python bytes to a string and back?

我正在寻找一种将字节转换为 python 字符串并返回的好方法,我已经尝试过

Sample_bytes = some_way_to_get_bytes()
output_str = ""
for i in Sample_bytes:
   output_str += str(i) + "%"

然后我会通过以下方式转换为字节:

output_bytes = b""
a = b""
for i in sample_str:
   if i == "%":
      output_bytes += a
      a = b""
   else:
      a += int(i).ConvertToBytes()

我用了一个假设的

int.ConvertToBytes()

function,有没有办法将 int 转换为 python 中的字节?

现在尝试关闭它,感谢您帮助我学习 python:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM