想把python变量转换成字符串插入到html代码中, 用 %s 的方式,尝试了不习惯,是需要把html的一些符号全转译吗
HighChart = '''
$(function(){
Highcharts.setOptions({"global": {}, "lang": {}});
var option = {
"chart": {
"renderTo": "container"
},
"colors": {},
"credits": {
"enabled": false
},
"exporting": {},
"labels": {},
"legend": {},
"loading": {},
"navigation": {},
"navigator": {},
"plotOptions": {
"series": {
"compare": "percent"
}
},
"rangeSelector": {
"selected": 4
},
"scrollbar": {},
"series": {},
"subtitle": {},
"title": {"text": "A New Highchart"},
"tooltip": {
"pointFormat": "{series.name}: {point.y} ({point.change}%)
", "valueDecimals": 2
},
"xAxis": {},
"yAxis": {
"labels": {
"formatter": function () {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
"plotLines": [{"value": 0, "width": 2, "color": "silver"}]
}
};
var chart = new Highcharts.StockChart(option);
var data = "%s";
var dataLen = data.length;
for (var ix = 0; ix < dataLen; ix++) {
chart.addSeries(data[ix]);
}
});
'''
HighChart % 'daddada'
ValueError: unsupported format character ')' (0x29) at index 1480
有什么好的办法?