I am using exec to save a variable equal to a string. I am getting a SyntaxError. I'm assuming exec is getting confused with the value as string. Is this assumption accurate? Would appreciate the learnings! If I changed each question to an str(int), the code will work. Any help is much appreciated.
json_template = {
"Introduction" : {
"What is your Department?" : "",
"What is your Name?" : "",
"What is your Email?" : ""
},
"Context" : {
"What is the necessary action or change?": "",
"What is the urgency?" : "",
"What lead to this change?" : "",
"What is the opportunity or pain point this action solves?" : ""
}
}
for each_category in json_template:
for index, each_question in enumerate(json_template[each_category]):
left_side = each_category + str(index)
right_side = each_question
bigstring = '='.join([left_side, right_side])
exec(bigstring)
print(bigstring)
Error below:
exec(bigstring) File "<string>", line 1 Introduction0=What is your Department? ^^^^^^^^^^