- 论坛徽章:
- 4
|
回复 13# gaomeng1447
下面代码应当基本可用,问题是不清楚最开始的re.sub是要做什么代换,原来代码的re.sub就去掉了。- import sys, re
- from util import *
- def ReadFromFile(file):
- title=True
- result = ['<html><head><title>...</title></head><body>']
- with open(file, 'r') as fh:
- for block in blocks(fh):
- if title:
- block = '<h1>' + block + '</h1>'
- result.append(block)
- title=False
- else:
- result.append('<p>')
- result.append(block)
- result.append('</p>')
- result.append('</body></html>')
- return result
- def WriteToFile(file, content):
- with open(file, 'w') as fh:
- fh.write("\n".join(content))
- def main():
- WriteToFile(sys.argv[2], ReadFromFile(sys.argv[1]))
- if __name__ == '__main__':
- main()
复制代码 |
|