Python:引用表中的行

Python:引用表中的行,python,html,html-table,Python,Html,Html Table,我试图从一个文件中提取行,并将它们放入一个表中,该表将显示在web上。我需要能够单独引用这些行,以使用if…else语句更改表信息 有人能帮我找到一种方法来引用这些行吗?这是我到目前为止的代码 #for each line in emaildomains - print out on page to view print '<form method=\'post\' name="updateUsers">' print '<table border="1">' print

我试图从一个文件中提取行,并将它们放入一个表中,该表将显示在web上。我需要能够单独引用这些行,以使用if…else语句更改表信息

有人能帮我找到一种方法来引用这些行吗?这是我到目前为止的代码

#for each line in emaildomains - print out on page to view
print '<form method=\'post\' name="updateUsers">'
print '<table border="1">'
print '<tr>'
print '<th>Email Address</th>'
print '<th>Delete Email</th>'
print '<th>Make Changes?</th>'
print '</tr>'
n=1
for line in emaildomains:
    print '<tr>'
    print '<td><input type="text" name=\"useraddress\", n, value ="%s">' %line
    print '<input type="hidden" name=useraddress_org value ="%s"></td>' %line
    print '<td><input type=\"radio\" name=\"deleteRadio\", n, style=margin-left:50px></td>'
    print '<td><input type="submit" value="Edit Users" /></td>'
    print '</tr>'
    n+=1
print '</table>'
print '</form>'
#对于emaildomains中的每一行-在页面上打印以查看
打印“
打印“
打印“
打印“电子邮件地址”
打印“删除电子邮件”
打印“进行更改?”
打印“
n=1
对于emaildomains中的行:
打印“
打印“”%行
打印“”%行
打印“
打印“
打印“
n+=1
打印“
打印“

为每个表条目(或行,取决于您的需要)设置一个
id
HTML属性。例如


利用格式字符串。例如,如果我想有条件地添加问候语,我会将变量默认为空字符串,并根据我的情绪进行更改。此外:

    <>而不是实例化和维护计数器,考虑使用枚举().<
  • 尽量避开转义字符
  • 保持干净一致的样式(例如,您有一些html属性使用',一些使用',还有一个不使用任何东西)
例如:

#for each line in emaildomains - print out on page to view
table_fs = """
<form method="post" name="updateUsers">
%s
<table border="1">
<tr>
<th>Email Address</th>
<th>Delete Email</th>
<th>Make Changes?</th>
</tr>
%s
</table>
</form>
"""

line_fs = """
<td>
  %s
  <input type="text" name="useraddress" %s value ="%s">
  <input type="hidden" name="useraddress_org" value ="%s">
</td>
<td><input type="radio" name="deleteRadio", n, style=margin-left:50px></td>
<td><input type="submit" value="Edit Users" /></td>
"""

good_mood = ''
if i_have_cookies:
    good_mood = '<h1>I LOVE COOKIES!</h1>'

lines = []
for n, line in enumerate(emaildomains, 1):
    greeting = ''
    if i_like_this_persion:
        greeting = 'Hi!'
    line = []
    line.append(line_fs%(greeting, n, line, line))
    cells_string = '\n'.join(['<td>%s</td>'%x for x in line])
    row_string = '<tr>%s</tr>'%(cells_string)
    lines.append(row_string)

rows_string = '\n'.join(lines)
print table_fs%(good_mood, rows_string)
#对于emaildomains中的每一行-在页面上打印以查看
表_fs=“”
%
电子邮件地址
删除电子邮件
做出改变?
%
"""
行_fs=“”
%
"""
好心情
如果我有饼干:
好心情=‘我喜欢饼干!’
行=[]
对于n,枚举中的行(emaildomains,1):
问候语=“”
如果我喜欢这个角色:
问候语=‘嗨!’
行=[]
行。追加(行(问候语,n,行,行))
单元格\u字符串='\n'。加入(['%s'%x,用于第x行])
行字符串=“%s%”(单元格字符串)
行。追加(行\字符串)
行\u字符串='\n'。连接(行)
打印表格(心情好,行和字符串)
还有,时间有点晚了,我有点累,所以如果我不能拼写,或者我遗漏了什么,我很抱歉

#for each line in emaildomains - print out on page to view
table_fs = """
<form method="post" name="updateUsers">
%s
<table border="1">
<tr>
<th>Email Address</th>
<th>Delete Email</th>
<th>Make Changes?</th>
</tr>
%s
</table>
</form>
"""

line_fs = """
<td>
  %s
  <input type="text" name="useraddress" %s value ="%s">
  <input type="hidden" name="useraddress_org" value ="%s">
</td>
<td><input type="radio" name="deleteRadio", n, style=margin-left:50px></td>
<td><input type="submit" value="Edit Users" /></td>
"""

good_mood = ''
if i_have_cookies:
    good_mood = '<h1>I LOVE COOKIES!</h1>'

lines = []
for n, line in enumerate(emaildomains, 1):
    greeting = ''
    if i_like_this_persion:
        greeting = 'Hi!'
    line = []
    line.append(line_fs%(greeting, n, line, line))
    cells_string = '\n'.join(['<td>%s</td>'%x for x in line])
    row_string = '<tr>%s</tr>'%(cells_string)
    lines.append(row_string)

rows_string = '\n'.join(lines)
print table_fs%(good_mood, rows_string)