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




Python File handling and File Operation

Python tutorials




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



  1. Python file handling is very important
  2. Python perform various function for creating , reading ,updating , deleting files.
  3. fopen() function is use to open the file
  4. "r" - For open file for read mode error if file dose not exist
  5. "a" - For open file for append create new file if dose not exist
  6. w" - For open file for write create new file if dose not exist
  7. "x" - Create new file if dose not exist error if file exists
  8. "t" - Default Text mode
  9. "b" - Binnary type(eg.Images)
  10. 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")







I hope You really enjoyed this blog . I try my best to make every thing is easy and helpfull to provide to public .You will get more blog about the Programing project and code . Thanks for visiting my blog if you have any querry related to this you can comment here i will try my best to response you back about Python File handling and File Operation  |  Python tutorials  Bestitworriors