MCPcopy Index your code
hub / github.com/python/cpython / get_field

Method get_field

Lib/string/__init__.py:300–316  ·  view source on GitHub ↗

Find the object referenced by a given field name. The field name *field_name* can be for instance "0.name" or "lookup[3]". The *args* and *kwargs* arguments are passed to get_value().

(self, field_name, args, kwargs)

Source from the content-addressed store, hash-verified

298 return _string.formatter_parser(format_string)
299
300 def get_field(self, field_name, args, kwargs):
301 """Find the object referenced by a given field name.
302
303 The field name *field_name* can be for instance "0.name"
304 or "lookup[3]". The *args* and *kwargs* arguments are
305 passed to get_value().
306 """
307 first, rest = _string.formatter_field_name_split(field_name)
308 obj = self.get_value(first, args, kwargs)
309 # loop through the rest of the field_name, doing
310 # getattr or getitem as needed
311 for is_attr, i in rest:
312 if is_attr:
313 obj = getattr(obj, i)
314 else:
315 obj = obj[i]
316 return obj, first

Callers 1

_vformatMethod · 0.95

Calls 1

get_valueMethod · 0.95

Tested by

no test coverage detected