프로그래밍/Python
[python] How to write to an HTML file in Python
홍반장水_
2022. 2. 25. 22:53
반응형
[python] How to write to an HTML file in Python
https://www.kite.com/python/answers/how-to-write-to-an-html-file-in-python
Kite - Free AI Coding Assistant and Code Auto-Complete Plugin
Code faster with Kite’s AI-powered autocomplete plugin for over 16 programming languages and 16 IDEs, featuring Multi-Line Completions. Works 100% locally.
www.kite.com
USE open() AND file.write() TO WRITE TO AN HTML FILE
Use open(file, mode) with mode as "w" to create a new HTML file file or write to an existing one. Use file.write(data) to write data to the file. Use file.close() to close the file after writing.
text = '''
<html>
<body>
<h1>Heading</h1>
</body>
</html>
'''
file = open("sample.html","w")
file.write(text)
file.close()
SAMPLE.HTML
<html>
<body>
<h1>Heading</h1>
</body>
</html>
반응형