不了解此TypeError:无法连接'str'和'int'对象异常

时间:2019-02-18 20:44:33

标签: python string int typeerror quotes

我得到了错误: TypeError: cannot concatenate 'str' and 'int' objects 在运行下面的代码时。它涉及年,月和日为整数,并且引号内包含引号。我的Python版本是2.7,因为我在没有管理员权限的工作计算机上工作,所以我无法更新Python。

import os

#input1 is the first date, input2 is the second date, with a 1 day
difference
yearinput1 = input("What's the start year?")
monthinput1 = input("What's the start month?")
dayinput1 = input("What's the start day?")
yearinput2 = input("What's the end year?")
monthinput2 = input("What's the end month?")
dayinput2 = input("What's the end day?")

print"sudo mam-list-usagerecords -s \" ", yearinput1, "-" , monthinput1, "-", dayinput1, " \" -e \" ", yearinput2, "-" + monthinput2, "-", dayinput2, " \" --format csv --full"

1 个答案:

答案 0 :(得分:1)

在打印对帐单中,您有以下内容:

<a  class="fe" href="#Z" >Fohnen...</a>
<a class="ae" href="#X" >Snowboarden</a>
<a class="af" href="#Y" >Programmeren</a> <a 
class="da" href="#W" >ING</a>

"-" + monthinput2 是一个整数,而monthinput2是一个字符串。您可以将"-"转换为字符串:

monthinput2