如何将变量标识符设置为另一个变量的内容?

时间:2022-12-22 23:50:08

I am trying to implement something in batch into Python as I am currently halfway through converting a batch game into syntax python can use.

我正在尝试批量实现Python,因为我目前正在将批量游戏转换为语法python可以使用。

FOO='YEET'
(FOO)='BAR'
print(YEET)

and then the desired output is

然后所需的输出是

>>>BAR

If you know batch here is the equivalent code as it may help you answer better. This works and is what I am trying to convert into python.

如果你知道批处理这里是相同的代码,因为它可以帮助你更好地回答。这是有效的,我正在尝试转换为python。

SET FOO=YEET
SET %FOO%=BAR
ECHO %YEET%

and of course then output:

当然然后输出:

> BAR

1 个解决方案

#1


3  

foo = 'YEET'
vars = {} # a dict
vars[foo] = 'BAR'
print(vars['YEET'])

#1


3  

foo = 'YEET'
vars = {} # a dict
vars[foo] = 'BAR'
print(vars['YEET'])