Python 3.x 减去Python36的值

Python 3.x 减去Python36的值,python-3.x,Python 3.x,我尝试从请求中减去值。get(“”) test.txt=5 我试着减去5-1 我的代码: count1 = requests.get('http://link/test.txt') @client.event async def on_ready(): await client.change_presence(game=discord.Game(name='test : '+ str(count1.text) - int(1), type=1)) 我想得到5-1=[最终结果为:4]作为bot

我尝试从请求中减去值。get(“”)

test.txt=5

我试着减去5-1

我的代码:

count1 = requests.get('http://link/test.txt')

@client.event
async def on_ready():
await client.change_presence(game=discord.Game(name='test : '+ str(count1.text) - int(1), type=1))
我想得到5-1=[最终结果为:4]作为bot状态“test:4”


TypeError:-:“str”和“int”的操作数类型不受支持


您需要将字符串转换为数字:

count1 = requests.get('http://link/test.txt')

@client.event
async def on_ready():
    await client.change_presence(game=discord.Game(name='test : ' + str(int(count1.text) - 1), type=1))

4
转换成
str
我试过了,好的未知错误我更新了错误。类型错误:不支持的操作数类型-:'str'和'int',{如果我使用str},,,,,类型错误:必须是str,而不是int{如果我使用int}。@Darzy08将减法结果转换回
str
。我更新了我的答案非常感谢,最终我知道了它是如何工作的,谢谢你提供的好信息