如何删除' ['']'从字符串中写成txt,仅在文本中写
我的Java中的代码在txt中写了什么,但是我希望它保存“标签”而没有字符'['']',最终与标签一起出现,谁能帮助我? '''
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)
'''
打印>> nome:aaatynqsi.karzono.com ID:305480378 IP:192.241.141.16标签:['aaatynqsi']
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']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的问题来看,它看起来像
标签
是一个字符串 - 但是您的评论说这是list
。您可以从列表中提取第一个项目(在这种情况下,只有项目)From your question, it looks like
tags
is a string - but your comment says it is alist
. You can extract the first item (in this case, only item) from the list with unpacking您可以打开标签列表,如下所示: -
但是,如果列表中有两个或多个元素,则可能不会给出所需的结果
You could unpacks the tags list as follows:-
However, this may not give the desired results if there are two or more elements in the list