5 ms·
Looks neat! Pattern matching is one of those features that I sorely miss when I have to program in Python. I do feel a bit wary seeing this[1] though, given th
by bow_ 8y ago
Looks neat! Pattern matching is one of those features that I sorely miss when I have to program in Python.
I do feel a bit wary seeing this[1] though, given that `_` can be considered a special character in Python. I suppose you can use `ANY` instead of `_` in the pattern matches, but of course that would not look as clean.
[1] https://github.com/santinic/pampy/blob/4c8e6e0cabada82a5ed794f935e9a6d249d2833a/pampy/pampy.py#L9 https://github.com/santinic/pampy/blob/4c8e6e0cabada82a5ed79...
- olooney 8y agoI agree. Lots of Python programmers use "_" as a variable name to indicate (by convention) that they don't intend to use the variable yet are syntactically required to give it a name[1]. Some common examples: for _ in range(10): ... red, _, _ = rgb(color) first, *_, last = some_list This convention conflicts with the use of a global variable named "_" because the first time a programmer uses this convention and rebinds "_" to something arbitrary it will mask the "_" imported from pampy. Of course a programmer is free to give it a more conventional name: from pampy import _ as placeholder But for my money pampy should have given "_" a real name and left it up to the programmer to give it a short alias if so desired: from pampy import placeholder as _ This is in line with common conventions around say, numpy, which is conventionally aliased to the shorter "np" on import: import numpy as np [1]: https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python https://stackoverflow.com/questions/5893163/what-is-the-purp... EDIT: So it turns out that pampy already has a more explicitly named alternative to "_" called "ANY". So anybody who doesn't like the _ syntax can use "from pampy import ANY" and use that instead.