Combining text files like how 'include' in PHP works using python -


i combine text files how include works in php.

a piece of code fine existing solution or package job preferred.

here trying accomplish in detail.

for example, main.html

<html> <body>    <header>    <<<include header.html>>>    </header>    content     <footer>    <<<includ footer.html>>>    </footer> </body> </html> 

header.html , footer.html contain partial html.

and after running python script, have new file called processed.html generated 3 files combined.

thank in advance!

import re html = open("main.html").read() match in re.findall('\<<<include.*?\>>>',s):     name = match.replace("<<<include ","").replace(">>>","")     content = open(name).read()     html = html.replace(match,content)  open("processed.html","w").write(html) 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -