Python Notes Application - File Read and Write operations

Published November 14, 2021

In this python example code we are going to create a simple Python Notes app where user can write his notes into file using file write operation and read notes from the file with file read operations.

In this python notes app example we will give use to options like

1 : Create Notes with New File
2 : Display Notes form the File
3 : Add extra notes to existing File

 

Then will ask user to enter his options

if he enter 1 we will create a new file and take user notes into notes variable and write into file

selection = int(input("Enter your option : "))
if selection == 1:
    notes = raw_input("Enter your Notes : ")
    file = open("Notes.txt","w")
    file.write(notes +"\n")
    file.close()

 

If user enter input 2 we will read the notes and display it

if selection == 2:
    file=open("Notes.txt","r")
    print(file.read())

 

If user enter input 3 we will add extra notes to the eixisting file

if selection== 3:
    file=open("Notes.txt","a")
    notes = raw_input("Enter your Notes : ")
    file.write(notes + "\n")
    file.close()
    file=open("Notes.txt","r")
    print(file.read())

 

Complete example code for Python notes app with File read and write operations

print ("1 : Create Notes with New File")
print ("2 : Display Notes form the File")
print ("3 : Add extra notes to existing File")
selection = int(input("Enter your option : "))
if selection == 1:
    notes = raw_input("Enter your Notes : ")
    file = open("Notes.txt","w")
    file.write(notes +"\n")
    file.close()
elif selection == 2:
    file=open("Notes.txt","r")
    print(file.read())
elif selection== 3:
    file=open("Notes.txt","a")
    notes = raw_input("Enter your Notes : ")
    file.write(notes + "\n")
    file.close()
    file=open("Notes.txt","r")
    print(file.read())
else:
    print("Please select option in 1,2 and 3")

 

Output:

Option 1

1 : Create Notes with New File
2 : Display Notes form the File
3 : Add extra notes to existing File
Enter your option : 1
Enter your Notes : This is My First Notes on day 14th

 

Option 2:

1 : Create Notes with New File
2 : Display Notes form the File
3 : Add extra notes to existing File
Enter your option : 2
This is My First Notes on day 14th

 

Option 3:

1 : Create Notes with New File
2 : Display Notes form the File
3 : Add extra notes to existing File
Enter your option : 3
Enter your Notes : This day i have create Python File Read and write operations
This is My First Notes on day 14th
This day i have create Python File Read and write operations

 

Conclusion: In this python tutorial example create Python notes app with File read and write operations

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

728 Views