Message380921
It would be nice if there were a way to get a string representation of a slice object in extended indexing syntax, e.g.
```
>>> myslice = slice(None, None, 2)
>>> print(myslice)
'::2'
```
One motivating use-case is in descriptive error messages, e.g.
```
TypeError(f"Can't slice {myobj}, try list({myobj})[{myslice}]")
```
In this case, it is much more natural for `myslice` to use the extended indexing syntax than the slice str/repr.
Perhaps this could be done via __str__, or if that is too big a change, maybe via __format__ e.g. `f"{myslice:asidx}"`
It's simple enough to write a conversion function, but this feels like a feature that would fit best upstream. I searched the issue tracker, PRs on GitHub, and the Python documentation and didn't see any related issues/PRs/articles.
xref: https://github.com/networkx/networkx/pull/4304 |
|
Date |
User |
Action |
Args |
2020-11-13 18:47:56 | rossbar | set | recipients:
+ rossbar |
2020-11-13 18:47:56 | rossbar | set | messageid: <1605293276.23.0.88839506976.issue42352@roundup.psfhosted.org> |
2020-11-13 18:47:56 | rossbar | link | issue42352 messages |
2020-11-13 18:47:56 | rossbar | create | |
|