A record keep app with delete function that I wrote using Python programming language it demonstrate text file database programming. I hope you will like it.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.Please subscribe to my channel https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg
Thank you very much for your support.
Program Listing
# record keeping app with delete function in python
# Jake Rodriguez Pomperada, MAED-IT, MIT
# www.jakerpomperada.com and www.jakerpomperada.blogspot.com
# jakerpomperada@gmail.com
# Bacolod City, Negros Occidental Philippines
import os
import sys
from pathlib import Path
class Records:
def __init__(self, choice):
self.choice = choice
if choice == "A":
with open("record.txt", "r") as records:
for last_line in records:
pass
if last_line[0] == "#":
num = 1
else:
num = int(last_line[0]) + 1
name = input("Enter Name: ")
email = input("Enter Email: ")
address = input("Enter Address: ")
with open("record.txt", "a") as writeRecord:
writeRecord.write(f"{num}\t\t\t{name}\t\t\t{email}\t\t\t{address}\n")
elif choice == "B":
with open("record.txt", "r") as countRecords:
count = len(countRecords.readlines()[1:])
if count == 0:
print("There are no records!!")
print()
else:
with open("record.txt", "r") as readRecords:
print(readRecords.read())
elif choice == "C":
record_id = input("Enter Record #: ")
with open("record.txt", "r") as f:
lines = f.readlines()
with open("record.txt", "w") as readRecords2:
for line in lines:
if not line.startswith(record_id):
readRecords2.write(line)
print("Record Deleted.")
elif choice == "D":
print("No records found.")
with open("record.txt", "r+") as f:
f.truncate(0)
elif choice == "E":
sys.exit("Thank you!")
else:
print("Invalid response. Please try again.")
while True:
def createFile():
with open("record.txt", "w+") as create:
create.write("#\t\t\tName\t\t\t Email\t\t\t Address\n")
if Path("record.txt"):
if os.stat("record.txt").st_size != 0:
with open("record.txt", "r+") as readFirstLine:
first = readFirstLine.readlines()[0][0]
if first != "#":
readFirstLine.write("#\t\t\tName\t\t\t Email\t\t\t Address\n")
else:
createFile()
else:
createFile()
print("==========================================================")
print(" ~ Record Keeping App With Delete Function in Python ~")
print("===========================================================")
print("Available Operators:")
print("A) Add Record\t\tB) View Record")
print("C) Delete record\tD) Clear Records")
print("E. Exit\n")
selection = input('Enter selection: ').upper()
Records(selection)
No comments:
Post a Comment