Home > Software engineering >  How to update a python string variable into a JSON file - ERROR: TypeError: bad operand type for una
How to update a python string variable into a JSON file - ERROR: TypeError: bad operand type for una

Time:01-03


    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.

CodePudding user response:

It should be:

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

just remove sign

  • Related