Python: add triple doc quotes and handle expansion of `"|"`

please add a docstring on what this does.