模拟静态类型语言中发现的方法重载是pythonic吗?因此,我的意思是写一个函数,检查其参数的类型,并根据这些类型行为不同。模拟方法重载是Pythonic吗?
下面是一个例子:
class EmployeeCollection(object):
@staticmethod
def find(value):
if isinstance(value, str):
#find employee by name and return
elif isinstance(value, int):
#find employee by employee number and return
else:
raise TypeError()
我想你忘记了添加'self'作为第一个参数 – 2011-06-18 05:39:57
实际上,它本意是一个静态方法。我现在更新了它。 – hwiechers 2011-06-18 09:28:58