I am trying to extract data from excel to postgresql using python 3.6 and pgadmin 4. Here is a part of my code that is failing.
if dataCentersName not in dataCenters:
dataCenters.add(dataCentersName)
query1 += "('" + str(dataCentersIdx) + "', '" + str(dataCentersName) + "'),"
dataCentersDict[dataCentersName] = dataCentersIdx
dataCentersIdx += 1
The error is at the comma after the last data center showing below ('8', 'DataCenter_8'),
It says: Error %s % e syntax error at end of input
Thank you very much!
-
You can string variable you want to replace in your script: Look this example: v = 'your'; 'Hello wath's %s name' % (v)Fabe– Fabe2017年12月26日 14:28:41 +00:00Commented Dec 26, 2017 at 14:28
-
And look again: query1 += ("%s %s %s) % (var_1, var_2, var_3)Fabe– Fabe2017年12月26日 14:30:48 +00:00Commented Dec 26, 2017 at 14:30
1 Answer 1
As you have a , at the end of your query, the query is awaiting for something else, that doesn't come hence the syntax error.
If you want to add a comma at the end of your loop as you're doing right now, you might want to send query1[:-1] (ignores the last character, the comma here), instead of query1 that I am sure you are sending as is.