Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8057623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:05:27+00:00 2026-06-05T09:05:27+00:00

I am trying to use finally in the following function, however, Python reports a

  • 0

I am trying to use finally in the following function, however, Python reports a Syntax error. I’m sure I’m doing something silly, but I can’t seem to spot it …

Snippet follows below:

# Store ids with key
# Returns GUID (used to clear table after words)
def storeIdsInTemporaryTable(dbinfo, id_list):
    conn = dbinfo['db_connection']

    guid = genutils.getGUID()
    orig_tableinfo = dbinfo['table']
    orig_datarows = dbinfo['datarows']

    metadata = dbinfo['metadata']

    sql = "INSERT INTO temporary_data_key (key) VALUES ({0}) RETURNING id".format(guid)
    key_id = executeSQLonDbConnection(dbinfo, sql, return_field='id')

    tableinfo = Table('temporary_data', metadata, autoload=True)
    datarows = []

    for id_value in id_list:
        datarows.append( { 'key_id': key_id, 'id_value': id_value} )

    try:
        insertToDb(dbinfo)
    except:
        guid = None # to indicate an error occured
        if key_id:
            conn.execute("DELETE FROM temporary_data_key WHERE key={0}".format(guid)

    finally:
        dbinfo['table'] = orig_tableinfo
        dbinfo['datarows'] = orig_datarows

    return guid

What is causing the syntax error?

As an aside, I am aware that I need to wrap the two inserts in a transaction, but for some reason, I can’t get transactions to work (SQLALchemy throws a transaction related error) – so thats for another question another time..

[[Edit]]

The exception error (now fixed) was:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/script.py", line 1632
    finally:
          ^
SyntaxError: invalid syntax
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:05:29+00:00Added an answer on June 5, 2026 at 9:05 am

    You’re missing a closing parenthesis in your call to execute(). It should be:

    conn.execute("DELETE FROM temporary_data_key WHERE key={0}".format(guid))
    

    Instead of:

    conn.execute("DELETE FROM temporary_data_key WHERE key={0}".format(guid)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use rspec with mongoid but I'm running across this error: undefined
I was trying use svn to find a checkin using svn log, but it
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
When installing packages in Python using pip, I came across the following error: unable
I'm trying to use the following code bellow to fire multiple thread to consume
I'm trying to implement the following operation in Java and am not sure how:
I am trying to use Qt for a project in school but am running
Hey guys, i'm trying to use the following drawing logic: Class Game { Character
The following setup kind of works, but it's not the proper use of TempData,
I am trying to write a simple function for windows that answers the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.