Python: Using vars() to assign a string to a variable

前端 未结 6 1880
南笙
南笙 2020-11-27 17:09

I find it very useful to be able to create new variables during runtime and create a dictionary of the results for processing later, i.e. writing to a file:

         


        
6条回答
  •  难免孤独
    2020-11-27 17:39

    Using vars / locals or globals in this way is (a) poor practice and (b) doesn't work in all cases. See Dynamically set local variable for more details. Bottom line: just use dicts -- that's what they're for.

提交回复
热议问题