是否可以使用Python代码创建局部变量,只给出变量的名称(字符串),以便后续调用locals()中的"'xxx'"将返回True?
这是一个视觉:
>>> 'iWantAVariableWithThisName' in locals()
False
>>> junkVar = 'iWantAVariableWithThisName'
>>> (...some magical code...)
>>> 'iWantAVariableWithThisName' in locals()
True
Run Code Online (Sandbox Code Playgroud)
出于什么目的,我需要这个技巧完全是另一个话题......
谢谢您的帮助.