Referencing and setting variables in Python dicts

后端 未结 3 847
感情败类
感情败类 2021-01-17 03:19

I want to use a python dict to store variable references and be able to assign the values pointed out by those references.

foo = \"foo\"
d = {\'foo\' : foo}
         


        
3条回答
  •  一生所求
    2021-01-17 04:03

    You can use setattr(profile, "mtoder_autoalpha", newvalue) as an alternative to the settings dict. The way you do it won't work as you expect because strings(and booleans and tuples ...) are immutable, so when you change it its a new string you are creating, not editing the 'original' object/variable.

提交回复
热议问题