@contextmanager
def temporary_locale(temp_locale=None):
 orig_locale = locale.setlocale(locale.LC_ALL)
 if (temp_locale is not None):
  locale.setlocale(locale.LC_ALL, temp_locale)
 (yield)
 locale.setlocale(locale.LC_ALL, orig_locale)

@ contextmanager def temporary_locale ( temp_locale = None ) : orig_locale = locale . setlocale ( locale . LC_ALL ) if ( temp_locale is not None ) : locale . setlocale ( locale . LC_ALL , temp_locale ) ( yield ) locale . setlocale ( locale . LC_ALL , orig_locale )
enable code to run in a context with a temporary locale resets the locale back when exiting context .