相关疑难解决方法(0)

如何连接str和int对象?

如果我尝试执行以下操作:

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)

我怎样才能解决这个问题?

python string concatenation python-2.x python-3.x

60
推荐指数
2
解决办法
8万
查看次数

无法连接'str'和'instance'

我有一个使用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基本上来自文本框.

python tkinter concatenation

7
推荐指数
1
解决办法
1万
查看次数

TypeError: can only concatenate str (not "int") to str 这是什么意思?

def myFunc(King):
    print("The characters name is " + King.name + " and age is " + King.age)
Run Code Online (Sandbox Code Playgroud)

如何将 int 链接到字符串?

python python-3.x

2
推荐指数
1
解决办法
2万
查看次数

Python无法连接'str'和'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)

python xml mysql parsing

-1
推荐指数
1
解决办法
6465
查看次数

标签 统计

python ×4

concatenation ×2

python-3.x ×2

mysql ×1

parsing ×1

python-2.x ×1

string ×1

tkinter ×1

xml ×1