All web application are having a important part its called File Handling. Python has several functions for creating,reading,updating, deleting files.
Syntax :
f = open("demofile.txt")
Example :
f = open("demofile.txt", "r") print(f.read())
Write to an Existing File:
f = open("demofile.txt", "w") f.write("Woops! I have deleted the content!")
Create a New File:
f = open("myfile.txt", "x")
Delete a File using os.remove() function:
import os os.remove("demofile.txt")
import os
if os.path.exists("demofile.txt"):
os.remove("demofile.txt")
else:
print("The file does not exists")
Liked By
Write Answer
File Handling
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Prakash nidhi Verma
06-Jul-2018File Handling:
All web application are having a important part its called File Handling. Python has several functions for creating,reading,updating, deleting files.
Syntax :
f = open("demofile.txt")Example :
f = open("demofile.txt", "r")print(f.read())
Write to an Existing File:
f = open("demofile.txt", "w")
f.write("Woops! I have deleted the content!")
Create a New File:
f = open("myfile.txt", "x")Delete a File using os.remove() function: