Valid characters in a python class name

前端 未结 4 714
暗喜
暗喜 2020-11-28 15:56

I\'m dynamically creating python classes, and I know not all characters are valid in this context.

Is there a method somewhere in the class library that I can use t

4条回答
  •  一整个雨季
    2020-11-28 16:27

    As per Python Language Reference, §2.3, "Identifiers and keywords", a valid Python identifier is defined as:

    (letter|"_") (letter | digit | "_")*
    

    Or, in regex:

    [a-zA-Z_][a-zA-Z0-9_]*
    

提交回复
热议问题