0
pythonとhtmlを使用して2つのカラムを作成しようとすると問題があります。だから、私はただ2つの列と任意の行を持つことができます。PythonとHTMLテーブルの作成
これは私のpythonのコードです::ここで私が作るしようとしているものの視覚的である
file_name = 'test.html'
test_file = open('test.html', 'w')
test_file.write('''<!DOCTYPE html>
<html>
<head>
<title> Dogs </title>
</head>
<body>
<table width="500" border="2" cellpadding="5">
''')
dog_names = ['Bob', 'Kenny', 'Robin', 'Ben', 'Tom', 'Steve']
dog_amount = len(dog_names)
index = 0
while dog_amount > index:
name = dog_names[index]
test_file.write(''' <tr>
<td align="center" valign="center">
<p>''' + name + '''</p>
</td>
</tr>\n''')
index += 1
test_file.write(''' </table>
</body>
</html> ''')
、これはhtmlファイルで作成されたものである。
<!DOCTYPE html>
<html>
<head>
<title> Dogs </title>
</head>
<body>
<table width="500" border="2" cellpadding="5">
<tr>
<td align="center" valign="center">
<p>Bob</p>
</td>
</tr>
<tr>
<td align="center" valign="center">
<p>Kenny</p>
</td>
</tr>
<tr>
<td align="center" valign="center">
<p>Robin</p>
</td>
</tr>
<tr>
<td align="center" valign="center">
<p>Ben</p>
</td>
</tr>
<tr>
<td align="center" valign="center">
<p>Tom</p>
</td>
</tr>
<tr>
<td align="center" valign="center">
<p>Steve</p>
</td>
</tr>
</table>
</body>
</html>