I am trying to create a library management software. I want to dynamically create an instance of class Library.
class Library(object):
def __init__(self,name,book_list):
self.name = name
self.book_list = book_list
def lend(self,book,stdname):
if book in self.book_list:
print(f"Book name: {book} lend to {stdname}")
self.book_list.remove(book)
else:
print(f"Book name: {book} not present currently")
def accept(self,book):
print(f"Thanks for using our services")
self.book_list.append(book)
class Student(Library):
def __init__(self,name,due):
self.name = name
self.due = due
def borrow(self,book_name):
if self.due == 0:
libname = input("Enter the name of library from which book has to be given: ")
if libname in globals():
globals()[libname].lend(book_name,self.name)
self.due+=1
else:
print(f"Sorry {libname} is not regeistered with our system")
else:
print("Sorry you have already borrowed a book from us")
def returnBook(self,book_name):
if self.due == 1:
libname = input("Enter the name of library form which book was given: ")
if libname in globals():
globals()[libname].accept(book_name)
self.due -=1
else:
print(f"Sorry {libname} is not regeistered with our system")
else:
print("OOPS we dont have any book given to you currently!")
while True:
command = input("Enter you Command here:")
if command.upper() == "/REGISTER":
libname = input("Enter the name of library: ") #can be say Books
libviewname = input("Enter the viewname of library: ") #must be lib1
booklist = eval(input("Enter the book_list: ")) # a list conatining some books as string can be ["Booka","Bookb","Bookc"]
#here i want to create an instance of class Library like: libviewname = Library(libname,booklist)
elif command.upper() == "/REGISTER_STD":
stdname = input("Enter the name of student :")
stdviewname = input("Enter the viewname of student: ")
dueinfo = int(input("Enter amount of due: "))
stdviewname.Student(stdname,stdviewname)
well the code is not complete. Here when user enter /register then he/she will have to provide 3 things. 1. Name of library 2. Identifier for instance 3. List of book available
when given then i want to make a instance like identifier = Library(Name of library,List of books)
For example if i get following values:
libviewname = "lib1"
libname = "Libraryworld"
booklist = ["Book_A","Book_B"]
then i want to pass it like:
lib1 = Library(libname,booklist)
Thanks for help!