My config: Python 3.9, Pycharm CE 2023.3.2, on Windows 10 Pro. I’m using Qt Designer and pyuic6 6.4.2. I’m new to Python and have not yet completed a 62 hour tutorial on Python. (I’m using Python 3.9 for the long tutorial I’m doing. I will upgrade Python later.)
In the Python tutorial I’m doing I’m creating long SQL statements and using a multi-line f string to make them like this:
cursor = self.conn.cursor()
sql = (f'UPDATE products SET name={name}, price={price}, ' +
'description={description} WHERE id={product_id}')
print("Update: SQL=" + sql)
cursor.execute(sql)
self.conn.commit()
But when the code is executed the program throws an error because after the first line the {variables} do not put in the values.
Is it possible to do a multi-line f string? Or do I have to do it the more wordy way like this?
sql = 'UPDATE products SET name=' + name + ', price=' + str(price) + ', ' +
'description=' + description + ' WHERE id=' + str(product_id)
I’d like to put the SQL in a variable for debugging purposes.
Thank you!
EDIT: I have tried these things also:
sql = 'UPDATE products SET name=' + name + ', price=' + str(price) + ', ' \
'description=' + description + ' WHERE id=' + product_id
sql = "UPDATE products SET name={}, price={}, description={} "
"WHERE id={}".format(name,price,description,product_id)
sql = "UPDATE products SET name={}, price={}, description={} "+
"WHERE id={}".format(name,price,description,product_id)
They all get some type of error.