Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Python File handling and File Operation | Python tutorials Bestitworriors
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Python File handling and File Operation | Python tutorials Bestitworriors
Python File handling and File Operation
Python File handling and File Operation | Python tutorials Bestitworriors - File handling is very important to any programing langauge . File handling is very effictive part we use in python.We can perform various function for creating,reading,Updating,deleting files.Python use fopen() function to open the file.
Some key Points of Python File Handling
- Python file handling is very important
- Python perform various function for creating , reading ,updating , deleting files.
- fopen() function is use to open the file
- "r" - For open file for read mode error if file dose not exist
- "a" - For open file for append create new file if dose not exist
- w" - For open file for write create new file if dose not exist
- "x" - Create new file if dose not exist error if file exists
- "t" - Default Text mode
- "b" - Binnary type(eg.Images)
- Python return one line using readline()
Code
file = open("months.txt", "r")
print(file.read())
file1 = open("D:\\myfiles\months.txt", "r")
print(file1.read())
file2 = open("months.txt", "r")
print(file2.readline())
file3 = open("months.txt", "r")
for x in file3:
print(x)
file4 = open("months.txt", "r")
print(file4.readline())
file5 = open("months.txt", "a")
file5.write("All months end data")
file5.close()
import os
if os.path.exists("months.txt"):
os.remove("months.txt")
else:
print("The file does not exist")
0 Comments