my code in java is writing in a txt what is in the print, but I would like it to save the "tag" without the characters '[' ']', which end up coming along with the tag, can anyone help me? '''
sleep(1)
#tags = r.tags
ip_address = droplet_response.json()['droplet']['networks']['v4'][0]['ip_address']
tags = droplet_response.json()['tags']
tag = tags.split([''])
print('Nome:',r.name, 'ID:',r.id, 'IP:',ip_address, 'TAG:',tags)
'''
print>> Nome: aaatYnqSi.karzono.com ID: 305480378 IP: 192.241.141.16 tag: ['aaatYnqSi']
CodePudding user response:
From your question, it looks like tags
is a string - but your comment says it is a list
. You can extract the first item (in this case, only item) from the list with unpacking
tags = ['aaatYnqSi']
clean_tag, *_ = tags
print(clean_tag)
# 'aaatYnqSi'
CodePudding user response:
You could unpacks the tags list as follows:-
print('Nome:',r.name, 'ID:',r.id, 'IP:',ip_address, 'TAG:',*tags)
However, this may not give the desired results if there are two or more elements in the list