Is there a way to create a global variable from a string? I know that you can make a variable from a string like so:
string = 'hello'
val = 10
vars()[string] = val
Thus making hello a variable equal to 10. I do not know how to make that user input variable global however, this does not work:
string = 'hello'
val = 10
vars()[string] = val
eval("global " + string)
You can use the
globals()function: