[英]How can I make my text not surrounded by ['']?
我在 python + discord.py 中使用 readlines 功能,但是我在嵌入中的值被 [''] 包圍。 出於顯而易見的原因,我想將其從我的嵌入中刪除
snipeduser = open("snipes/snipeduser.txt", "r").readlines()
snipedchannel = open("snipes/snipedchannel.txt", "r").readlines()
snipedserver = open("snipes/snipedserver.txt", "r").readlines()
snipedmessage = open("snipes/snipedmessage.txt", "r").readlines()
snipedmessagetime = open("snipes/snipedmessagetime.txt", "r").readlines()
embed = discord.Embed(title="Message Sniped!", color=0xE71D36)
embed.set_author(name=f"Message sent by {snipeduser}!")
embed.add_field(name=f"Channel",value=f"{snipedchannel}", inline=True)
embed.add_field(name=f"Server", value=f"{snipedserver}", inline=True)
embed.add_field(name=f"Message", value=f"{snipedmessage}", inline=False)
embed.set_footer(text=f"Time of Message Deletion {snipedmessagetime}")
await ctx.send(embed=embed)
順便說一句,代碼工作正常,除了 [''] 問題
這是一個例子;
['我的 Discord ID(我的 Discord 標簽)'] 發送的消息!
消息被截斷!
渠道
['我的私人頻道 ID(機器人測試)']
服務器
['我的私人服務器']
信息
['測試']
留言刪除時間
['2020-11-11 21:34:08.330000']
readlines()
function,如果你閱讀文檔 ( https://docs.python.org/3/tutorial/inputoutput.html ) 返回一個列表。 該列表是您獲得['.....']
output 的原因。
所以你想要的是獲取每個列表的第一個元素,例如snipeduser[0]
而不是snipeduser
。
試試這個。 :
with open(filename) as f:
content = f.readlines()
# If you also want to remove whitespace characters like `\n` at the end of each line
text = [x.strip() for x in text]
要么
with open('filename') as f:
lines = f.readlines()
我使用join()
來做這樣的事情。 join() 字符串方法通過連接可迭代的所有元素返回一個字符串,由字符串分隔符分隔,在這種情況下分隔符只是一個空白。
value=''.join(yourvaluehere)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.