Search code examples
pythondjangopython-2.7python-3.xtornado

how can I split a string and store it in a temporary variable


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

Solution

  • 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