I've been very proud of myself of not having to ask any questions yet as I learn python. However, I can't seem to figure this one out.
I'm attempting to append data taken from json.dump, keep it until the loop is satisfied, and then add all of the numbers that were appended.
Below is a piece of my code (you can make fun of me, I'm sure it's horrendous). The purpose is: if text is equal to response text, parse the the json dictionary and enter a level. Once in the "orderFillTransaction" level, take the value of "pl" and append.
if 'orderFillTransaction' in json_data:
print("Json_Data:", type(json_data))
Closed_ID2 = json_data['orderFillTransaction']
PL_List = (Closed_ID2['pl'])
print("PL_List:", PL_List, type(PL_List))
PL.append(PL_List)
print("PL.append:", PL, type(PL))
Below is the output:
Json_Data: <class 'dict'>
PL_List: -0.1300 <class 'str'>
PL.append: ['-0.1300', '-0.1300'] <class 'list'>
The problem is, if I try to sum(), it errors out, if I float() I get some weird numbers; I just can't seem to figure out how to add each of the items together. If it matters, the numbers are usually negative.
Often time's I either get the errors below:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
or
ValueError: invalid literal for int () with base 10
I know it has something to do regarding a str inside a list instead of an int, however, I know there has to be some solution.
Any direction would be greatly appreciated. Thank you!