Created
October 12, 2017 06:00
-
-
Save techsharif/e3986e68ebc90a4a10e38186497d6e06 to your computer and use it in GitHub Desktop.
PYTHON_store_and_search_data_for_start_learning
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 get_data(): | |
students = [] | |
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) | |
student = {'name':name, 'id':id_, 'phone':phone} | |
students += [student] | |
return students | |
def show_data(): | |
students = get_data() | |
for student in students: | |
print(student) | |
def show_data_by_id(id_): | |
students = get_data() | |
for student in students: | |
if int(student['id']) == int(id_): | |
print(student) | |
break | |
print("No data found at roll",id_) | |
def select(): | |
sp.call('clear',shell=True) | |
sel = input("1. Add data\n2.Show Data\n3.Search\n4.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:") | |
elif sel=='3': | |
sp.call('clear',shell=True) | |
id__ = int(input('Enter Id: ')) | |
show_data_by_id(id__ ) | |
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