-4

I have a data, which is nothing but a string b'365,7,7675962680, 4040.I want to split this data and want to store only 7675962680 to any temporary variable.I don not know, how to split and pick that particular data in python. I have a small code, please help me to solve these issue

manage.py

def data(self, data):
    data1 = data # b'365,7,7675962680, 4040
    # want to split these and store 7675962680 in a variable
joy
  • 39
  • 4
  • Note the question about "convert a string to ip address" - it looks like you're working on the same exercise at the same time. – TigerhawkT3 Mar 31 '17 at 10:31

3 Answers3

1

You can use something like this:

def get_data(data):
    data = data.decode()
    data_list = data.split(',')
    return data_list[2]

a = get_data(b'365,7,7675962680, 4040')
print(a)
>> 7675962680
Yuval Pruss
  • 8,716
  • 15
  • 42
  • 67
0

assuming,

s ="365,7,7675962680, 4040"
s.split(',')[2]
'7675962680'
Surajano
  • 2,688
  • 13
  • 25
0
def data(self, data):
    # data = b'365,7,7675962680, 4040
    # data MUST be converted to str before splitting it
    data1 = data.decode('utf8').split(',')[2]
    print(data1)  # 7675962680
    print(type(data1))  # str
nik_m
  • 11,825
  • 4
  • 43
  • 57