Created
October 8, 2017 06:35
-
-
Save techsharif/1e15295928f6abb51169c9b071f09b61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess as sp | |
def add_data(id_,name,phone): | |
data = "{:10d}{:60s}{:15s}".format(id_,name,phone) | |
print(data) | |
file = open('db.txt','a') | |
file.write(data) | |
file.close() | |
def show_data(): | |
file = open('db.txt','r') | |
data = file.read() | |
file.close() | |
# print(data) | |
ln = len(data) | |
for i in range(int(ln/85)): | |
start = i*85 | |
end = start + 85 | |
student_info = data[start:end] | |
id_ = student_info[0:10].strip() | |
name = student_info[10:70].strip() | |
phone = student_info[70:85].strip() | |
print("id:",id_,"name:",name,"phone:",phone) | |
def select(): | |
sp.call('clear',shell=True) | |
sel = input("1. Add data\n2.Show Data\n3.Exit\n\n") | |
if sel=='1': | |
sp.call('clear',shell=True) | |
id_ = int(input('id: ')) | |
name = input('Name: ') | |
phone = input('phone: ') | |
add_data(id_,name,phone) | |
elif sel=='2': | |
sp.call('clear',shell=True) | |
show_data() | |
input("\n\npress enter to back:") | |
else: | |
return 0; | |
return 1; | |
while(select()): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment