Created
September 18, 2021 18:31
-
-
Save Elijah-trillionz/6ffbb754c2ae6b7e439c941bce850786 to your computer and use it in GitHub Desktop.
Handling files in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: python delete file and folders | |
import os | |
# create file | |
html = open('demo.html', 'x') | |
html.close() | |
# write to new file | |
html = open('demo.html', 'w') | |
html.write('<html>\n<body>\n<p>\nHello World</p>\n</body>\n</html>') | |
html.close() | |
# read | |
html = open('demo.html') | |
print(html.read()) | |
# append | |
html = open('demo.html', 'a') | |
html.write('</>') | |
html.close() | |
# read update file | |
html = open('demo.html') | |
print(f'Updated HTML is \n {html.read()}') | |
html.close() | |
# check if file exists before deleting | |
if os.path.exists('demo.html'): | |
os.remove('demo.html') | |
print('HTML successfully created, written on, read, appended on, and deleted. Thank you for learning Python') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment