MCPcopy Index your code
hub / github.com/python-openxml/python-docx / __getitem__

Method __getitem__

src/docx/styles/styles.py:31–47  ·  view source on GitHub ↗

Enables dictionary-style access by UI name. Lookup by style id is deprecated, triggers a warning, and will be removed in a near-future release.

(self, key: str)

Source from the content-addressed store, hash-verified

29 return any(style.name_val == internal_name for style in self._element.style_lst)
30
31 def __getitem__(self, key: str):
32 """Enables dictionary-style access by UI name.
33
34 Lookup by style id is deprecated, triggers a warning, and will be removed in a
35 near-future release.
36 """
37 style_elm = self._element.get_by_name(BabelFish.ui2internal(key))
38 if style_elm is not None:
39 return StyleFactory(style_elm)
40
41 style_elm = self._element.get_by_id(key)
42 if style_elm is not None:
43 msg = "style lookup by style_id is deprecated. Use style name as key instead."
44 warn(msg, UserWarning, stacklevel=2)
45 return StyleFactory(style_elm)
46
47 raise KeyError("no style with name '%s'" % key)
48
49 def __iter__(self):
50 return (StyleFactory(style) for style in self._element.style_lst)

Callers

nothing calls this directly

Calls 4

StyleFactoryFunction · 0.90
ui2internalMethod · 0.80
get_by_nameMethod · 0.45
get_by_idMethod · 0.45

Tested by

no test coverage detected