Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- # Function definitions
- def create_database(database_name):
- if os.path.exists(database_name):
- print('Error: database already exists')
- else:
- os.mkdir(database_name)
- print(f'{database_name} Database created successfully')
- def create_table(database_name,table_name,table_header):
- table_name = table_name + '.txt'
- file_name = '.\\' + database_name + '\\' + table_name
- if os.path.exists(file_name):
- print('Error: table already exists')
- else:
- file = open(file_name,'a') # '.\\' + database_name + '\\' + table_name .\student_db\student_tb.txt
- file.write(table_header+'\n')
- file.close()
- print(f'{table_name} Table created successfully')
- def insert_data(database_name,table_name,data):
- table_name = table_name + '.txt'
- file_name = '.\\' + database_name + '\\' + table_name
- if not os.path.exists(file_name):
- print('Error: table does already exists')
- else:
- file = open(file_name,'a') # '.\\' + database_name + '\\' + table_name .\student_db\student_tb.txt
- file.write(data+'\n')
- file.close()
- print('Data inserted successfully')
- def select_data(database_name,table_name):
- table_name = table_name + '.txt'
- file_name = '.\\' + database_name + '\\' + table_name
- if not os.path.exists(file_name):
- print('Error: table does already exists')
- else:
- file = open(file_name,'r') # '.\\' + database_name + '\\' + table_name .\student_db\student_tb.txt
- data = file.readlines()
- file.close()
- data = data[1:]
- for line in data:
- print(line)
- # Program Start Here!
- create_database('student_db')
- create_table('student_db','student_tb','id name age viber gmail')
- #insert_data('student_db','student_tb','1#aung#093848498#aung@gmail.com')
- #insert_data('student_db','student_tb','2#maung#0934598#maung@gmail.com')
- #insert_data('student_db','student_tb','3#ko ko#093856498#koko@gmail.com')
- #insert_data('student_db','student_tb','4#su su#093823498#susu@gmail.com')
- select_data('student_db','student_tb')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement