- 编辑 - 添加了我的员工类
方法只处理类中的信息(属性)吗?可以使用方法处理来自外部的信息吗? 我怎样才能“宣传”莎拉?所以我必须创建sarah员工实例,但如何让经理来推广她呢?
class Employee:
"""Base infromation about any emploee"""
def __init__(self, name, last_name, birthdate, email, phone,
social_sec_no, credit_card, level):
self.name = name
self.last_name = last_name
self.birthdate = birthdate
self.email = email
self.phone = phone
self.social_sec_no = social_sec_no
self.credit_card = credit_card
self.level = level #level 1-3 for laborer, 4- administration, 5 - plant manager
class PlantManager(Employee):
"""Plant manager:
- Approves budget
- Promotes
- Gives order to hire - fire person
"""
def __init__(self, name, last_name, birthdate, email, phone,
social_sec_no, credit_card, level):
super().__init__(name, last_name, birthdate, email, phone,
social_sec_no, credit_card, level)
def promotion(self, employee_lvl):
if employee_lvl == 3:
return
else:
employee_lvl = employee_lvl + 1
manager = PlantManager('John', 'Stockton', '1989-05-15', 'taas@yahoo.com', '+17068645474',
'5847-487-0', '222 484 999', 5)
sarah = 1
print(manager.promotion(sarah)) #returns None
答案 0 :(得分:1)
如果您想宣传员工,您需要通过提供员工来指定哪一个。
{{field.label(class="control-label " + (
" col-%s-%s" % horizontal_columns[0:2]
))|safe}}
然后你可以宣传它们。
class PlantManager(Employee):
...
def promotion(self, employee):
if employee.level >= 3:
raise ValueError('not allowed to promote') # better to raise than silently fail
else:
employee.level += 1
答案 1 :(得分:0)
你必须制作一个名为Sarah的对象,如:
Sarah = Employee('sarah', 'name', '1989-05-15', 'taas@yahoo.com', '+17068645474',
'5847-487-0', '222 484 999', 5)
然后你可以调用促销方法来提高等级:
Sarah.level = Manager.promote(Sarah.level)
还应编辑PlantManager
的提升方法,以便返回最终值。
使用新信息进行编辑。
答案 2 :(得分:0)
您的函数提升不会返回else部分中的值