In Python, How can I put results of a class to a dictionary? I want a table of employees with their names, IDs , date of work, arrival times. I’ve written a class for date in this format .. 12-Feb-2013 and time like this 08:51:14 Now how can I show all these in a dictionary?
monthName = [' ', 'Jan', 'Feb', 'Mar', 'Apr', 'May',
'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
monthDays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def showTitle (dic: dict):
for i in dic.keys():
print (i,end="\t\t")
print ("\n===================================")
class Date:
def getdate(self):
self.y = int(input("Year: "))
self.m = int(input("Month: "))
EndDay = monthDays[self.m]
if self.m == 2 and self.isLeap():
EndDay += 1
self.d = int(input("Day: "))
while (self.d < 1 or self.d > EndDay):
print("Error")
self.d = int(input("Day: "))
def __init__(self, a=1900, b=1, c=1):
self.y = a
self.m = b
self.d = c
def show(self):
print(f"{self.y}/{self.m}/{self.d}")
def show1(self):
print(f"{self.d} - { monthName[self.m]} - {self.y}")
def isLeap(self):
if self.y % 400 == 0:
return True
if self.y % 100 != 0 and self.y % 4 == 0:
return True
return False
#-------------Time-------------------
class Time :
def show ( self ) :
print (f"{self.h}:{self.m}:{self.s}")
def gettime( self ):
self.h = int (input ("Hour :"))
while self.h < 0 or self.h > 23 :
self.h = int (input ("Hour :"))
self.m = int (input ("Minute :"))
while self.m < 0 or self.m > 59 :
self.m = int (input ("Minute :"))
self.s = int (input ("Second :"))
while self.s < 0 or self.s > 59 :
self.s = int (input ("Second:"))
def showFull ( self ) :
if self.d > 0 :
print( self.d , end=" Day " )
if self.h < 10 :
print( "0",end="" )
print (self.h , end=":")
if self.m < 10 :
print( "0",end="" )
print (self.m , end=":")
if self.s < 10 :
print( "0",end="" )
print (self.s )
def set ( self , a=0 , b=0 , c=0 ) :
self.h = a
self.m = b
self.s = c
self.m += self.s // 60
self.s %= 60
self.h += self.m // 60
self.m %= 60
self.d += self.h // 24
self.h %= 24
def __init__( self , a=0 , b=0 , c=0 ):
self.d = 0
self .set ( a ,b, c )
def showDict (dic: dict):
for i in dic.keys():
print (dic [i],end="\t\t")
def getDict ():
dic= dict ()
dic ['id']= int (input ("Enter ID: "))
dic ['Name']= input ("Enter Name: ")
dic ['Family']= input ("Enter Family: ")
dic ['Date']= int (input ("Enter Date: "))
dic ['Arr']= int (input ("Enter Arrival Time: "))
dic ['Dep']= int (input ("Enter Departure Time: "))
return dic
d = Date()
d.getdate()
d.show1()
print()
t= Time ()
t.gettime ()
t.showFull()
t.set()
print()
emplolist = list()
for i in range (2):
info = dict ()
info = getDict ()
emplolist.append (info)
showTitle (emplolist [0])
for i in range (2):
showDict(emplolist[i])
print ()
I want to show the date and time in the dictionary