我试图获取列表值并在类中使用它来构建htmltext。
我尝试使用此代码,但是我变成了错误的值,就像我的列表为空。
''''
test=["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17",
“ 18”,“ 19”,“ 20”,“ 21”,“ 22”,“ 23”,“ 24”,“ 25”,“ 26”,“ 27”,“ 28”,“ 29” ,“ 30”,“ 31”,“ 32”,“ 33”,“ 34”,“ 35”,“ 36”,“ 37”]
MyClass类(列表):
def __init__(self, number):
self.number = number
Edge4 = []
for i in range (len(Edge4)):
Edge4.append(number)
f = open('switch.html', 'a')
for i in range (len(Edge4)):
print(Edge4[i])
print(len(Edge4))
message5 = """ <html>
<head>
<style type="text/css">
body{{
background-color:#cfcfd1;
width:2000px;
height:auto;
}}
.main-container{36}{{
background-image: url(bas.png);
background-size: 100% 100%;
width: 900px;
padding: 4;
height: 100px;
margin-left:55;
position:absolute;
left:1000;
top:240;
}}
table.firstr{36}{{
width:250;
background-color:#2f343d;
margin-left: 55px;
margin-top: 25px;
float:left;
font-size:10;
font-weight:bold;
color:#b56f00;
table-layout:fixed;
overflow: hidden;
}}
table.seconder{36}{{
width:250;
background-color:#2f343d;
margin-left: 5px;
margin-top: 25px;
float:left;
font-size:10;
font-weight:bold;
color:#b56f00;
table-layout:fixed;
overflow: hidden;
}}
table.therd{36}{{
width:250;
background-color:#2f343d;
margin-left: 5px;
margin-top: 25px;
float:left;
font-size:10;
font-weight:bold;
color:#b56f00;
table-layout:fixed;
overflow: hidden;
}}
.switchname{36}{{
margin-top:70;
font-weight:bold;
width:120;
height:30;
color:black ;
margin-left:280;
font-size:25;
position:absolute;
left:1200;
top:140;
}}
</style>
</head>
</head>
<body>
<div class="switchname{36}">{36}</div>
<div class="main-container{36}">
<div class="firstr{36}">
<table class="firstr{36}" width="250" height="63" border="1">
<tbody>
<tr>
<td>{0} </td>
<td>{1}</td>
<td>{2}</td>
<td>{3}</td>
<td>{4}</td>
<td>{5}</td>
</tr>
<tr>
<td>{18}</td>
<td>{19}</td>
<td>{20}</td>
<td>{21}</td>
<td>{22}</td>
<td>{23}</td>
</tr>
</tbody>
</table>
<div class="seconder{36}">
<table class="seconder{36}" width="250" height="63" border="1">
<tbody>
<tr>
<td>{6}</td>
<td>{7}</td>
<td>{8}</td>
<td>{9}</td>
<td>{10}</td>
<td>{11}</td>
</tr>
<tr>
<td>{24}</td>
<td>{25}</td>
<td>{26}</td>
<td>{27}</td>
<td>{28}</td>
<td>{29}</td>
</tr>
</tbody>
</table>
</div>
<div class="therd{36}">
<table class="therd{36}" width="250" height="63" border="1">
<tbody>
<tr>
<td>{12}</td>
<td>{13}</td>
<td>{14}</td>
<td>{15}</td>
<td>{16}</td>
<td>{17}</td>
</tr>
<tr>
<td>{30}</td>
<td>{31}</td>
<td>{32}</td>
<td>{33}</td>
<td>{34}</td>
<td>{35}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
""".format(
str(Edge4[0][2:18]),
str(Edge4[2][2:18]),
str(Edge4[4][2:18]),
str(Edge4[6][2::]),
str(Edge4[8][2::]),
str(Edge4[10][2::]),
str(Edge4[12][2::]),
str(Edge4[14][2::]),
str(Edge4[16][2::]),
str(Edge4[18][2::]),
str(Edge4[20][2::]),
str(Edge4[22][2::]),
str(Edge4[24][2::]),
str(Edge4[26][2::]),
str(Edge4[28][2::]),
str(Edge4[30][2::]),
str(Edge4[32][2::]),
str(Edge4[34][2::]),
str(Edge4[1][2::]),
str(Edge4[3][2::]),
str(Edge4[5][2::]),
str(Edge4[7][2::]),
str(Edge4[9][2::]),
str(Edge4[11][2::]),
str(Edge4[13][2::]),
str(Edge4[15][2::]),
str(Edge4[17][2::]),
str(Edge4[19][2::]),
str(Edge4[21][2::]),
str(Edge4[23][2::]),
str(Edge4[25][2::]),
str(Edge4[27][2::]),
str(Edge4[29][2::]),
str(Edge4[31][2::]),
str(Edge4[33][2::]),
str(Edge4[35])[2::],
"Edge4")
def Writeme(self):
f.write(message5)
print(Edge4)
f.close()
for i in range (0,36):
MyClass(test)
print (MyClass)
'''
有没有办法将所有列表用作对象,或者有没有其他办法可以我使用
非常感谢