这是我的程序代码,但我有一个语法错误的问题,我不知道是什么问题。我得到的错误在print "employee / supervisor id :" ,k.get_id()," Date joined :" ,k.get_date()
语法错误与那行代码中的“”有关。你知道吗
`import datetime #this will import the formatting for date and tiem
class employee:
"""docstring for employee"""
def __init__(self, empid,loc,enttime):
self.empid = empid
self.enttime = enttime
self.exitime = None
self.date = None
self.loc = loc
def exittime(self,exitime):
self.exitime = exitime
def setdate(self,date):
self.date = date
def get_id(self):
return self.empid
def get_date(self):
return self.date
class supervisor(object):
"""docstring for supervisor"""
def __init__(self, supid,loc,enttime):
self.supid = supid
self.deptid =loc
self.enttime =enttime
self.exitime =None
self.date = None
def exittime(self,exitime):
self.exitime = exitime
def setdate(self,date):
self.date = date
def get_id(self):
return self.supid
def get_date(self):
return self.date
def printbydate(l):
l.sort(key=lambda x: x.date, reverse=True)
for k in l:
print "employee / supervisor id :" ,k.get_id()," Date joined :" ,k.get_date()
date1 = datetime.date(2015, 11, 20)
date2 = datetime.date(2017, 11, 27)
a = employee("e112","abc",12)
b = supervisor("s341","abc",14)
a.setdate(date1)
b.setdate(date2)
a.exittime(19)
b.exittime(19)
pil =[]
pil.append(a)
pil.append(b)
printbydate(pil)'
正如在this答案中指出的,
print
是python3中的一个函数,这意味着您需要将参数包装在括号中打印。你知道吗因此,这将修复您案例中的错误:
相关问题 更多 >
编程相关推荐