Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不理解此类型错误:无法连接'str'和'int'对象异常_Python_String_Int_Typeerror_Quotes - Fatal编程技术网

Python 不理解此类型错误:无法连接'str'和'int'对象异常

Python 不理解此类型错误:无法连接'str'和'int'对象异常,python,string,int,typeerror,quotes,Python,String,Int,Typeerror,Quotes,我得到一个错误: TypeError:无法连接'str'和'int'对象 当运行下面的代码时。它涉及到年、月和日是整数,并且引号中有引号。我的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?"

我得到一个错误: TypeError:无法连接'str'和'int'对象 当运行下面的代码时。它涉及到年、月和日是整数,并且引号中有引号。我的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"

在打印报表中,您有以下内容:

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

"-" + str(monthinput2)

欢迎来到StackOverflow!花点时间阅读一篇关于python中字符串格式的文章。这就足够了。