Я борюсь с какой-то проектной работой и думал, что кто-то может помочь мне здесь. Я пишу инструмент базы данных, и мне нужно иметь возможность найти значение идентификатора у человека в CSV-файле и изменить статус его сотрудника с активного на неактивный. Имея очень базовые знания Python, я борюсь с этим. Вот мой код, который работает сейчас.
def menu():
print("Welcome to the Employee database\n")
print("1. Add a new employee\n")
print("2. Remove an existing employee\n")
print("3. Change/modify the details of an existing employee\n")
print("4. Search and display the details for a particular employee\n")
print("0. Quit\n")
choice = int(input("Please select an option using the numbers above"))
if choice == 0:
return
if choice == 1:
add()
if choice == 2:
remove()
if choice == 3:
change()
if choice == 4:
search()
def add():
print("Adding a new employee, please enter the following details\n")
employee_id = int(input("Enter your employee ID\n"))
name = input("Enter your name\n")
department = input("Enter your department\n")
designation = input("Enter your designation\n")
joining_date = input("Enter your starting date [DD/MM/YYYY]\n")
employee_status = input("Enter the employee status [Active/Inactive]\n")
with open('database.csv', "a") as f:
employee_info = ""
employee_info += "%s," % employee_id
employee_info += "%s," % name
employee_info += "%s," % department
employee_info += "%s," % designation
employee_info += "%s," % joining_date
employee_info += "%s," % employee_status
employee_info += "\n"
f.write(employee_info)
menu()
Мне нужно, чтобы он мог получить от пользователя идентификатор, который он хочет сделать неактивным, найти нужного человека в csv и изменить его тег на неактивный. Возможно ли это?
Буду признателен за любую помощь!
Edit:
Вот содержимое файла csv
:
Employee ID,Name,Department,Designation,Joining Date,Employee Status
456,Matt,IT,Data,02/04/2018,Active
245,John,HR,Manager,30/04/2019,Active