如何删除' ['']'从字符串中写成txt,仅在文本中写

发布于 2025-02-10 08:59:40 字数 475 浏览 3 评论 0原文

我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白衬杉格子梦 2025-02-17 08:59:41

从您的问题来看,它看起来像标签是一个字符串 - 但是您的评论说这是list。您可以从列表中提取第一个项目(在这种情况下,只有项目)

tags = ['aaatYnqSi']
clean_tag, *_ = tags
clean_tag = clean_tag.strip()
print(clean_tag, end='')
# 'aaatYnqSi'

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
clean_tag = clean_tag.strip()
print(clean_tag, end='')
# 'aaatYnqSi'
秋千易 2025-02-17 08:59:41

您可以打开标签列表,如下所示: -

print('Nome:',r.name, 'ID:',r.id, 'IP:',ip_address, 'TAG:',*tags)

但是,如果列表中有两个或多个元素,则可能不会给出所需的结果

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文