Chezhiiyan Sabapathy
Chezhiiyan Sabapathy

Reputation: 33

How to update a python string variable into a JSON file - ERROR: TypeError: bad operand type for unary +: 'str'


    Var = "Jonathan"
    new_data = {"premium": + Var}
    json_object['classes'][states].update(new_data)

This was the code I used, the error I got was this: TypeError: bad operand type for unary +: 'str'

How can I work around this? In the actual code the string is not Jonathan, it is something that is created by the code.

Upvotes: 1

Views: 44

Answers (1)

Talha Tayyab
Talha Tayyab

Reputation: 27910

It should be:

Var = "Jonathan"
new_data = {"premium": Var}

just remove + sign

Upvotes: 1

Related Questions