我需要用反引號 `` 將每個串列元素括起來,以便代碼可以發送到前端。基本上,我需要用反引號替換單引號。以下是我需要進行更改的串列。
['<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<link
href="https://www.moneycontrol.com/rss/latestnews.xml"
rel="alternate"
title="MoneyControl.com News"
type="application/rss xml"
/>
</td>
</tr>
</table>',
'<table cellpadding="0" cellspacing="0" class="rhsglTbl" width="100%">
<thead>
<tr>
<th width="120">Index</th>
<th width="80">Price</th>
<th width="55">Change</th>
<th width="50">% Chg</th>
</tr>
</thead>
</table>']
需要進行此更改,以便我可以遍歷每個元素并將其添加到手風琴中。
uj5u.com熱心網友回復:
像這樣?
backticked = [ f"`{x}`" for x in your_list ]
使用額外資訊進行編輯
這將回傳一個串列,就像原始串列一樣,但是每個元素都有一個開始和結束的反引號,因此如果您將其寫入檔案以將其傳遞給前端,它將具有反引號
在你的 python 編輯器中,它將是
['`<table ... </table>`', '`<table ... `']
但是當您將其寫入前端檔案時,它將是
`<table>...</table>`
`<table>...</table>`
這是 JS 替換所需要的,不是嗎?
它還取決于您如何傳遞資料,您可能只在前端執行模板文字:
tableElement.innerHTML = `${ varFromPython }`
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/367484.html
