【问题标题】:how to write a list of data in HTML table using python如何使用python在HTML表格中写入数据列表
【发布时间】:2015-08-19 05:14:04
【问题描述】:

我已经建立了一个 HTML 表并想使用 python 代码编写数据。 这是代码:

 <body>
<h1 align="center">EXAMPLE</h1>
<table style="width:100%">


<tr>


<th width="17%" height="70">XYZ</th>
<th width="37%">XYZ</th>        
<th width="16%">XYZ</th>
<th width="16%">XYZ</th>
<th width="14%">XYZ</th>


</tr>

</table>

我想使用字符串和 python 代码输入表格数据。可以输入数据吗??

*这里这些XYZ值应该用字符串替换。

【问题讨论】:

  • 为什么不可能?但是你这样的问题很不清楚,你想写什么数据?你想写 where 的确切位置(我不是在问 table 中的 th/tr ,而是这个 html 到底在哪里?
  • HTML 位于我桌面的某个文件夹中。我想使用 Python 的字符串变量编写任何数据。假设我想在表头中写 TRAIN LIST 并想用 TRAIN LIST 替换这个 XYZ。我想将 HTML 文件导入 python 并用任何其他数据替换 XYZ。

标签: python html


【解决方案1】:

这可能有帮助

my_string = 'whatever you want'

with open('my.html') as html:
    html_data = html.read()
with open('new.html', 'w') as new_html:
    new_html.write(html_data.replace('XYZ', my_string))

【讨论】:

    猜你喜欢
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    • 2021-03-22
    相关资源
    最近更新 更多