python中getattr函数使用方法 getattr实现工厂模式

1168次阅读  |  发布于5年以前

看了下函数本身的doc

复制代码 代码如下:

getattr(object, name[, default]) -> value

Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8