File Handling using Python


Basic File Open Syntax.


Basic Syntax for 'with' and 'as' keyword while open a file:


Basic Syntax to show for loop to go through each line from the file.


Write Mode:

  • File can open in Write mode which works as Over Write file content with String you Pass in syntax.
Syntax:
with open('demo.txt') as file:
    file.write("String here")

  • Another important feature of write mode is that if file does not exist then it will be added empty file at the Current folder in which you are working.

Append Mode :

  • Files can open in append mode which includes write method.
Syntax :
with open('demo.txt", mode='a') as file:
    file.write("Appended String Here")


Comments

Popular posts from this blog

Program to Perform Calculator Function.

Turtle Crossing Project Using Turtle modules.

Check for Prime Number either between 1-100 or user-given