好的,所以我有一个 template.html 文件,如下所示:
<h1>Hello wolrd</h1>
<div>This is me</div>
我想在结束正文标记之前将其附加到我的索引文件中。就像这样:
<!doctype html>
<html>
<head>
  <meta charset="utf-8"/>
  <title></title>
</head>
<body>
<script type="text/ng-template" id="templates/template.html">
<h1>Hello wolrd</h1>
<div>This is me</div> 
</script>
</body>
</html>
到目前为止,我已经阅读了文件并附加到它的末尾,但是我还没有将脚本标签添加到我正在阅读的文件中并附加到我的文件的正确位置。这是我目前拥有的:
#!/usr/bin/env python
import fileinput
to_readfile=open('index.html', "r")
try:
  reading_file=to_readfile.read()
  writefile=open('index2.html','a')
  try:
    writefile.write("\n")
    writefile.write(reading_file)
  finally:
    writefile.close()
finally:
  to_readfile.close()
任何帮助将非常感激。谢谢!