从字符串中获取二进制数据

时间:2017-05-08 00:22:23

标签: python string python-3.x split byte

通过套接字发送一些信息后,我有一个如下所示的二进制对象:

b"1:b'5Q\x19aw\x17\x8c\x98\x10\x1c\xe0O\x14\xd1x\xa1'"

我想要做的是获取第一部分:作为字符串,第二部分作为二进制文件。像这样:

'1'

b'5Q\x19aw\x17\x8c\x98\x10\x1c\xe0O\x14\xd1x\xa1'

在我所有的尝试中,我最终得到了:

b"b'5Q\x19aw\x17\x8c\x98\x10\x1c\xe0O\x14\xd1x\xa1'"

或:

"b'5Q\x19aw\x17\x8c\x98\x10\x1c\xe0O\x14\xd1x\xa1'"

1 个答案:

答案 0 :(得分:1)

将其拆分为app.factory("ListWithTotal", ["$firebaseArray", function($firebaseArray) { // create a new service based on $firebaseArray var ListWithTotal = $firebaseArray.$extend({ getTotal: function() { var total = 0; // the array data is located in this.$list angular.forEach(this.$list, function(rec) { total += rec.amount; }); return total; } }); return function(listRef) { // create an instance of ListWithTotal (the new operator is required) return new ListWithTotal(listRef); } } ]); 并进行相应的解码和修剪:

b':'

现在:

i, j = r.split(b':')
i = i.decode()  #  '1'
j = j[2:-1]
相关问题