Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python在HTML表中编写数据列表_Python_Html - Fatal编程技术网

如何使用python在HTML表中编写数据列表

如何使用python在HTML表中编写数据列表,python,html,Python,Html,我已经建立了一个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

我已经建立了一个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值应使用字符串替换。

这可能会有所帮助

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))

为什么不可能呢?但你的问题本身很不清楚,你想写什么数据?我不是在问表中的th/tr,而是这个html具体驻留在哪里?这个html驻留在我桌面上的某个文件夹中。我想使用Python的字符串变量编写任何数据。假设我想在表头中写入列车列表,并想用列车列表替换此XYZ。我想将HTML文件导入python并用任何其他数据替换XYZ。