錯誤:我有一個很難理解爲什麼我在Python得到這個類型錯誤
TypeError: unsupported operand type(s) for +: 'int' and 'str'
當我的結果產生在我的Python代碼完美花車:
data = ",".join(str(x) for x in house_index_data)
0.12,0.29,0.13,0.12,0.23,0.13,0.07,0.21,0.22,0.18,0.11,0.18,0.16,0.07,0.20,
0.11,0.09,0.11,0.18,0.07,0.12,0.14,0.14,0.11,0.21,0.21,0.06,0.20,0.16,0.00,
0.14,0.12,0.04,0.10,0.12,0.13,0.11,0.21,0.22,0.08,0.11,0.12,0.08,0.00,0.13,
0.05,0.14,0.12,0.09,0.12,0.14,0.15,0.09,0.14,0.07,0.07,0.00,0.41,0.01,0.08,
0.08,0.09,0.10,0.21,...
@app.route('/main')
@login_required
def main():
# Data from .csv file
######################
base_dir = "db/"
logged_in_user = g.user
spreadsheet = pe.get_sheet(file_name=os.path.join(base_dir, "example.csv"))
house_index_data = [x.encode('ascii') for x in spreadsheet.column[48]]
print ",".join(str(x) for x in house_index_data)
# data = str(house_index_data).replace("'", "")
data = ",".join(str(x) for x in house_index_data)
# Graphs (Bar) data
#####################
bar_chart = pygal.StackedBar(fill=True, interpolate='cubic', style=BlueStyle)
bar_chart.title = 'Stack bar chart of House Index'
bar_chart.add('House Index', [data])
bar_chart.render()
return render_template('main.html',
user=logged_in_user,
value=spreadsheet,
bar_chart=bar_chart,
line_chart=line_chart)
這工作,但我使用的特定圖書館要求要麼浮動或詮釋 –
它看起來對我來說,變量'data'你創建的是一個字符串,當它被使用時,在'bar_char.add(...,[data])'它應該是一個浮動列表。你應該調用'bar_char.add(...,house_index_data)'而不是? – quamrana
因爲你沒有在你自己的代碼中使用'+'運算符,所以'TypeError'被引發。 – chepner