如果我尝试执行以下操作:
things = 5
print("You have " + things + " things.")
Run Code Online (Sandbox Code Playgroud)
我在Python 3.x中收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str, not int
Run Code Online (Sandbox Code Playgroud)
......以及Python 2.x中的类似错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我有一个使用GUI元素的程序并返回错误
cannot concatenate 'str' and 'instance' objects
Run Code Online (Sandbox Code Playgroud)
守则是:
def PeopleSearch():
query = SearchTerm
query = ('what is '+ query)
string = ("<center><font size = 14> " + query + ' </font></center><br><img src =picture')
j = 0
try:
gs = GoogleSearch(query)
gs.results_per_page = 100
results = gs.get_results()
Run Code Online (Sandbox Code Playgroud)
压痕已经改变.嗯.SearchTerm基本上来自文本框.
def myFunc(King):
print("The characters name is " + King.name + " and age is " + King.age)
Run Code Online (Sandbox Code Playgroud)
如何将 int 链接到字符串?
我正在尝试将XMLfile解析为mysqldb.这是xml
<categories>
<category id="28">Woman</category>
<category id="277" parentId="28">T-Shirts</category>
<category id="140" parentId="277">shorts</category>
</category>
Run Code Online (Sandbox Code Playgroud)
的.py
for category in categories:
for item in category.getElementsByTagName("category"):
category_name = item.childNodes[0].nodeValue.encode("utf-8")
category_id = int(item.getAttribute('id'))
category_parentId = item.getAttribute('parentId')
#connect etc
sqlFillCategories = "INSERT INTO categories(category_id, category_parentId, shop_id, category_name) VALUES ('"+category_id + "', '" + category_parentId + "', '" + TREND_BRANDS_SHOPID + "', '" + category_name + "');"
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "E:/python1/fanswell/parse.py", line 23, in <module>
sqlFillCategories = "INSERT INTO categories(category_id, category_parentId, shop_id, category_name) VALUES ('"+category_id …Run Code Online (Sandbox Code Playgroud)