1

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!

2
  • You can string variable you want to replace in your script: Look this example: v = 'your'; 'Hello wath's %s name' % (v) Commented Dec 26, 2017 at 14:28
  • And look again: query1 += ("%s %s %s) % (var_1, var_2, var_3) Commented Dec 26, 2017 at 14:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! Fixed my code and forgot to add that part again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.