data = 'red/x00XY/x001/x00168.93/x00859.07/x00' # I change "/" mark from "\" because i'm using Linux otherwise it will give error in Linux
new_list = [] # There is a variable that contain empty list
for item in data.split('/x00'): # Here I use split function by default it splits variable where "," appears but in this case
new_list.append(item) # you need list should be separated by "/" so that's why I gave split('/x00') and one by list appended
print(new_list)```
这段代码可以帮助您理解您是否希望使用pop()函数获得完全相同的输出
我们可以使用以下行:
一部分一部分地进行:
x.decode("utf8")
:x
将是一个字节字符串,因此我们需要通过“.decode”(“utf8”)将其转换为字符串李>for x in data.split(b"\x00")
:我们可以使用python内置的bytes.split
方法将字节字符串按空字节分割,以获得单个字符串的数组李>if len(x)
:这相当于if len(x) > 0
,因为我们希望丢弃结尾的空字符串李>相关问题 更多 >
编程相关推荐