我有一个变量data:
data = [b'script', b'-compiler', b'123cds', b'-algo', b'timing']
我需要转换它以删除列表中所有出现的“b”。 我该怎么做?
请您参考如下方法:
不确定它是否有帮助 - 但它适用于您的示例:
initList = [b'script', b'-compiler', b'123cds', b'-algo', b'timing']
resultList = [str(x) for x in initList ]
或者在 P3 中:
resultList = [x.decode("utf-8") for x in initList ] # where utf-8 is encoding used
在 decode function. 上查看更多信息
您可能还想看看 the following related SO thread.
