Pythonically check if a variable name is valid

后端 未结 6 2113
臣服心动
臣服心动 2020-12-29 07:37

tldr; see the final line; the rest is just preamble.


I am developing a test harness, which parses user scripts and generates a Python script which it then ru

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 07:52

    You could use exceptions handling and catch actually NameError and SyntaxError. Test it inside try/except block and inform user if there is some invalid input.

提交回复
热议问题