MCPcopy Index your code
hub / github.com/pyscript/pyscript / __getitem__

Method __getitem__

core/src/stdlib/pyscript/web.py:497–522  ·  view source on GitHub ↗

Get an item within this element. Behaviour depends on the key type: - Integer: returns the child at that index. - Slice: returns a collection of children in that slice. - String: looks up an element by id (with or without '#' prefix). ```python

(self, key)

Source from the content-addressed store, hash-verified

495 return isinstance(obj, Element) and obj._dom_element == self._dom_element
496
497 def __getitem__(self, key):
498 """
499 Get an item within this element.
500
501 Behaviour depends on the key type:
502
503 - Integer: returns the child at that index.
504 - Slice: returns a collection of children in that slice.
505 - String: looks up an element by id (with or without '#' prefix).
506
507 ```python
508 element[0] # First child.
509 element[1:3] # Second and third children.
510 element["my-id"] # Element with id="my-id" (or None).
511 element["#my-id"] # Same as above (# is optional).
512 ```
513 """
514
515 if isinstance(key, (int, slice)):
516 return self.children[key]
517 if isinstance(key, str):
518 return _find_by_id(self._dom_element, key)
519 raise TypeError(
520 f"Element indices must be integers, slices, or strings, "
521 f"not {type(key).__name__}."
522 )
523
524 def __getattr__(self, name):
525 """

Callers

nothing calls this directly

Calls 1

_find_by_idFunction · 0.85

Tested by

no test coverage detected