循环中列表项的引用部分



我正试图将一个txt文件转换成一个具有特定格式的新txt文件,这样我就可以直接把它放到一个网站上。

我已经创建了一个名为stats的项目列表,要在Statistics标题下进行,但我现在试图编写循环,告诉它以特定的方式格式化文本,我正在获得无效的语法错误。

这是我到目前为止所做的…

txt = open(html_file, 'a')
    txt.write('<h5><a href="http://www.learningplusuk.org/data/education-reform" target="_blank"><strong>Education Reform</strong></a></h5>'
            'n'
            '<p>All the latest information on qualification reform can be found via our website, in the ‘Education Reform’ section.</p>'
            'n'
            '<hr>'
            'n'
            '<p>Statistics and Data</p>'
            'n'
            '<hr>'
            'n')
for i in stats:
    j,k = enumerate(stats.split("t"))
txt.write('<h5><a href=/"'i.split("t")[4]'" target="_blank"><strong>'i.split("t")[1]'</strong></a></h5>'
            'n'
            '<h5><strong>'i.split("t")[2]'</strong></h5>'
            '<p>'i.split("t")[3]'<br></p>'
            '<hr>'
            'n')
txt.close()

但是它说i.split是无效的语法。有什么建议吗?

谢谢!

尝试在连接字符串时使用+运算符:'<h5><a href=/"' + i.split("t")[4] + '" target=...'

最新更新