Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to Object name

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
like image 847
Natsume Avatar asked Mar 04 '13 01:03

Natsume


1 Answers

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.

like image 186
Isaac Avatar answered Sep 21 '22 19:09

Isaac