• Offers
    • RegisterLogin
      • Learn More
    PythonPoint.netPythonPoint.net
    • Offers
    • RegisterLogin
      • Learn More

      Python

      SKILL IS IMPORTANT THAN DEGREE Be skill full.
      • Home
      • Blog
      • Python
      • What is File Handling in Python

      What is File Handling in Python

      • Posted by Python Point Team
      • Categories Python
      • Date December 31, 2022
      • Comments 0 comment
      what is file handling in python

      File handling is allowing the users to handle files i.e., to read and write files, along with many other file handling options, to operate on files.

      In Python, the files are treated as text or binary. Every line of a file is terminated with a special character, called the EOL or End of Line characters like comma or newline character. It ends the present line and tells the interpreter a brand new one has begun.

      open()

      The open() function in Python to open a file in read or write mode. open( ) will return a file object.

      The syntax : open(filename, mode).

      There are three kinds of mode. These shows how files can be opened:

      •  r , for reading.
      •  w , for writing.
      •  a , for appending.
      •  r+ , for both reading and writing
      file = open('test.txt', 'r') 
      
      for i in file: 
          print (i)

      read()

      If you need to extract a string that contains all characters in the file, then we can use file.read()

      file = open("test.txt", "r")  
      print (file.read()) 

      write()

      The write() mode will write to an existing file, or create a new file and write the contents to the new file.

      file = open('test.txt','w') 
      file.write("Sample command") 
      file.close()  #close() command terminates all the resources in use and frees 
                    #the system of this particular program
      • Share:
      author avatar
      Python Point Team

      Previous post

      What is Exception Handling in Python
      December 31, 2022

      Next post

      What is Float in Python
      December 31, 2022

      You may also like

      15 Powerful Step for Mastering JSON Parsing in Python: Boosting Data Manipulation and Validation
      21 June, 2023

      Introduction In the world of programming, data plays a crucial role, and managing it efficiently is of utmost importance. JSON (JavaScript Object Notation) has emerged as a popular data interchange format due to its simplicity and flexibility. In this article, …

      Introduction to Transfer Learning with Python: A Practical Guide
      31 December, 2022

      Introduction: Definition of transfer learning Overview of how transfer learning works in the context of machine learning Why transfer learning is useful and important Section 1: Transfer learning in Python with Keras In this section, we will explore how to …

      How to Check Type in Python
      31 December, 2022

      In this article, we will learn to check type in Python. The built-in function type() can be used to check the type of data in Python.

      Subscribe
      Login
      Notify of
      Please login to comment
      0 Discussion
      Inline Feedbacks
      View all comments

      Latest Courses

      (Hindi) Ways to earn minimum 1 Lakh Per month as Programmer

      (Hindi) Ways to earn minimum 1 Lakh Per month as Programmer

      ₹10,000
      (HINDI) Full Stack Web Development In Python 3.8 And Django 3.1

      (HINDI) Full Stack Web Development In Python 3.8 And Django 3.1

      ₹25,000 ₹2,500

      Latest Posts

      • 15 Powerful Step for Mastering JSON Parsing in Python: Boosting Data Manipulation and Validation
      • Introduction to Transfer Learning with Python: A Practical Guide
      • How to Check Type in Python
      • How to make web crawler in python?
      • Why was the language called “python”?
      Contact
      •   support@pythonpoint.com

      We get you the best Python Courses and Blogs aiming to provide skill.

      We Believe Skill is much more important than a Degree

      Company
      • About Us
      • Blog
      • Offers
      • Contact
      Useful Links
      • Courses
      Support
      • Need Support

      © 2020 ALL RIGHTS RESERVED​ PYTHONPOINT.NET

      PythonPoint

      • Terms of Use
      • Refund Policy
      • Privacy Policy

      Login with your site account

      Lost your password?

      Not a member yet? Register now

      Register a new account

      Are you a member? Login now

      wpDiscuz