how to solve tuple object has no attribute 'split error

Viewed 1704

I am trying to split the tuple data using below code but getting an error "AttributeError: 'tuple' object has no attribute 'split'".

request_number = ('1234567.t0',)

id = request_number.split(".")

print(id)

for i in range (len(id)):
    print (id[0])

Note: when I take input as a string it's working fine

1 Answers

Tuples have no split method, use a string, not a tuple. If the string is in a tuple, you can get it with slice e.g.

my_tuple[0].split('.')

In the case of the example, remove the brackets to get a string e.g.

request_number = '1234567.t0'
Related