Quantcast
Channel: MySQL Forums - Connector/Python
Viewing all articles
Browse latest Browse all 384

Python and MySql (3 replies)

$
0
0
Hello,

Currently I have a database (MySql) with a table called monedas where I have the following fields, simbolo and decimales.

Ae I am connecting to an API that generates a response of type dictionary.

I have saved the dictionary as a list to be able to obtain two values (simbolo and decimales), the code is as follows:

count = 0
all_symbols = [(symbol ["symbol"], symbol ["pricePrecision"]) for symbol in response ["symbols"]]
for symbol in all_symbols:
print (symbol [0], symbol [1])
count + = 1
symbol = symbol [0]
decimal = symbol [1]

In this case, I can obtain the two values correctly, but I cannot insert the new values that are different from the ones I have in the currencies table using the following code:

mycursor.execute("INSERT INTO monedap (simbolo, decimales) SELECT 'simbolo', decimales FROM monedas WHERE simbolo = %s and decimales = %s AND NOT EXISTS (SELECT * FROM monedas WHERE simbolo= ' ')", (simbolo, decimal))


Can someone suggest me what to do please.

Regards,

Orlando Gautier

Viewing all articles
Browse latest Browse all 384

Trending Articles