commonutil.fetch¶
值擷取輔助函數 / Value fetch functions
-
get_attrs(obj, *args)[source]¶ 取得複數個物件中的屬性,循序傳回結果
Get attribute from objects.
Parameters: - object – 要找尋屬性的物件 / Object to searching for attribute
- default_value (attr_name,) – 要找尋的屬性名稱字串與預設值 / Attribute name string and default values
Yields: 取出的屬性或預設值 / Fetched attribute value or default value
-
get_attrs_notnone(obj, *args)[source]¶ 取得複數個物件中的屬性,循序傳回結果。若取出值為 None 的話,則傳回預設值。
Get attribute from objects. Yields default value if fetched value is None.
Parameters: - object – 要找尋屬性的物件 / Object to searching for attribute
- default_value (attr_name,) – 要找尋的屬性名稱字串與預設值 / Attribute name string and default values
Yields: 取出的屬性或預設值 / Fetched attribute value or default value
-
get_attrs_notzero(obj, *args)[source]¶ 取得複數個物件中的屬性,循序傳回結果。若取出值為 0 的話,則傳回預設值。
Get attribute from objects. Yields default value if fetched value is 0.
Parameters: - object – 要找尋屬性的物件 / Object to searching for attribute
- default_value (attr_name,) – 要找尋的屬性名稱字串與預設值 / Attribute name string and default values
Yields: 取出的屬性或預設值 / Fetched attribute value or default value
-
get_by_keys(d, keys, default_value=None)[source]¶ 從給定的字典物件中依序利用指定的鍵串列取出值,傳回第一個非 None 的值。
如果都沒有非 None 的值,或是鍵都不存在,那就傳回指定的預設值。
Get value from given dictionary object and return first value which is not None.
If all mapped value is None or none of key exists, return given default value.
Parameters: - d (dict) – 要取值的字典物件 / Dictionary object to fetch value from
- keys (list of key) – 指定的鍵構成的串列 / List of key to fetch value for
- default_value=None – 預設值 / Default value
Returns: 第一個取得的值,或是當沒有辦法取得非 None 值時,傳回給定的預設值 / First non-None value mapped from given dictionary