How to convert a=b=2
string into a=2, b=2
(actual assignments) in python?
There are some python parsers which give output for expressions like 2+3+4
.
But how to use a=b=2
string into variable as a=2 b=2
?
How to convert a=b=2
string into a=2, b=2
(actual assignments) in python?
There are some python parsers which give output for expressions like 2+3+4
.
But how to use a=b=2
string into variable as a=2 b=2
?
s = 'a=b=2'
exec(s) #executes the string as a python command
And you are done
print(a)
2
print(b)
2
Refer to this discussion for more info: How do I execute a string containing Python code in Python?