[Python] How to enforce ASCII-only identifiers in Python while allowing UTF-8 strings?

Discussão em 'Python' iniciado por Stack, Janeiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I want to configure Python so that it raises an error when encountering non-ASCII characters in identifiers (e.g., variable names, function names) but still accepts UTF-8 encoded strings (e.g., "Привет, мир!"). For example:

    # This should raise an error
    def тест():
    pass

    # This should work
    text = "Привет, мир!"


    I know about # -*- coding: ascii -*-, but it blocks non-ASCII characters everywhere in the source code, including in string literals.

    (and also the same question for jupyter notebook)

    Continue reading...

Compartilhe esta Página