在 PHP 中,我可以这样做:
class MyClass
{
function __call($name, $args)
{
print('you tried to call a the method named: ' . $name);
}
}
$Obj = new MyClass();
$Obj->nonexistant_method(); // prints "you tried to call a method named: nonexistant_method"
能够在 Python 中为我正在处理的项目执行此操作会很方便(需要解析大量令人讨厌的 XML,将其转换为对象并能够调用方法会很好。
Python有等价物吗?