python variables

Hi I was wondering if it is possible to create a variable while the gameengine is running with a string from another variable eg. if you have a = “b” then i want to be able to create a variable called b : ((a) = 1) = b
something like that i hope you understand what i’m asking


I’m not sure what you want to do. I assume you want to create a variable named after a string. I don’t see the sense of it because you can use a dictionary. Dictionaries are lists of key/value pairs:

# create an empty dictionary
my_dict = dict()			

# the key
a = "some string"

# another key		
b = "some other string"	

# assigning values to the keys
my_dict[a] = "some value"			
my_dict[c] = "some other value"
my_dict["a third key"] = "a third value"

# assigns values to another variable
c = my_dict["some string"]		
d = my_dict["some other string"]
e = my_dict["a third key"]

# an example loop
for key, value in my_dict.items():
	print key, value

Check the python documentation for further explanation.

I hope it helps.

I think i have a Solution for You.

Own = Cont.getOwner()
Var = "String"

print Own.String
>>> Hello

I hope that helps. :smiley:
Cu, Doc