4 ms·
Maybe there should be a context manager?
by wyldfire 4y ago
Maybe there should be a context manager?
- nerdponx 4y agoAbsolutely. It's not that hard to write your own though: import locale from contextlib import contextmanager @contextmanager def use_locale(*args, **kwargs): locale.setlocale(*args, **kwargs) yield locale.resetlocale() Contextlib is one of the under-appreciated gems in Python: https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager https://docs.python.org/3/library/contextlib.html#contextlib...
- catskul2 4y ago> Maybe there should be a context manager? Even despite the: > Absolutely. My absolute least favorite response to this is: > It's not that hard to write your own though:
- nerdponx 4y agoThe alternative is trying to get one merged into the standard library. At least writing your own is better than not having one!
- catskul2 4y agoI often see this answer as a reason it's not particularly important to have on in a standard library. I strongly disagree with that sentiment as often these simple things have subtle gotchas, and/or subtle differences in possible net effects creating much bigger problems than their diminutive implementations would suggest.
- nerdponx 4y agoI generally feel the same way as you. My comment about getting it merged was not meant to imply that it shouldn't get merged, but that it might be difficult to. I find it very hard to predict which of these small QoL features will be accepted by the core devs and which features will be rejected for some reason or other.
- kzrdude 4y agoDoes not really help parallel code
- dolmen 4y agoUse a global lock in the context manager. Or use a programming language that doesn't rely on libc for locales.