Temporarily override locale with a context manager

前端 未结 3 985
有刺的猬
有刺的猬 2021-01-20 18:36

Is there a way to temporarily activate a locale within the scope of a block of code? Basically, I want to do something like this:

locale.setlocale(locale.LC_         


        
3条回答
  •  自闭症患者
    2021-01-20 19:16

    I found out that Babel better fits my use case:

    >>> parse_decimal('1,25', locale='nl_BE.utf8')
    Decimal('1.25')
    

    This approach is useful whenever I need to parse a Dutch decimal and doesn't require overriding any locales at all.

提交回复
热议问题