Python语法错误(“”)

2024-09-30 22:20:13 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的程序代码,但我有一个语法错误的问题,我不知道是什么问题。我得到的错误在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)'

Tags: selfnoneidforgetdatedefemployee
1条回答
网友
1楼 · 发布于 2024-09-30 22:20:13

正如在this答案中指出的,print是python3中的一个函数,这意味着您需要将参数包装在括号中打印。你知道吗

因此,这将修复您案例中的错误:

print("employee / supervisor id :" ,k.get_id()," Date joined :" ,k.get_date())

相关问题 更多 >