本文介绍了将字符串转换为对象名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这方面我需要帮助.如何将字符串转换为变量/对象/实例名称,因为我不知道如何对其进行分类.
假设我的代码是:

I needed help on this one. How do I convert a string into a variable/object/instance name, since I don't know how to categorize this.
Assuming my code is:

a = {}
b = {}

class Test:
    def getKeys(self, var):
        return var.keys() #where var refers to the dictionary and its a string initially

推荐答案

自从我用Python做过任何事情以来,这一直很长,但是我确实记得曾经遇到过这个问题.我建议您研究 eval() 函数.

It's been forever since I've done anything with Python but I do remember having this problem once. I suggest you look into the eval() function.

这篇关于将字符串转换为对象名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 02:38