News for hackers. Stuff that matters.
Re:ISO name change for Türkiye by wyldfire on Tuesday July 12, 2022 @09:06AM (#32069291)
Maybe there should be a context manager?
Re:ISO name change for Türkiye by nerdponx on Tuesday July 12, 2022 @11:36AM (#32071471)
Absolutely. 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...
Re:ISO name change for Türkiye by catskul2 on Tuesday July 12, 2022 @03:01PM (#32074309)
> 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:

Re:ISO name change for Türkiye by nerdponx on Tuesday July 12, 2022 @03:23PM (#32074526)
The alternative is trying to get one merged into the standard library. At least writing your own is better than not having one!
Re:ISO name change for Türkiye by catskul2 on Wednesday July 13, 2022 @10:03AM (#32082867)
I 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.

Re:ISO name change for Türkiye by nerdponx on Wednesday July 13, 2022 @11:59AM (#32084518)
I 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.
Re:ISO name change for Türkiye by kzrdude on Tuesday July 12, 2022 @11:41AM (#32071549)
Does not really help parallel code
Re:ISO name change for Türkiye by dolmen on Tuesday July 12, 2022 @12:36PM (#32072411)
Use a global lock in the context manager.

Or use a programming language that doesn't rely on libc for locales.