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

  • Home
  • SEARCH
  • 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 7828351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:19:32+00:00 2026-06-02T10:19:32+00:00

I am working at getting SQLalchemy to do some tasks for me via python.

  • 0

I am working at getting SQLalchemy to do some tasks for me via python.

I can sort of get it working by following examples, but I have been stuck for a while now on moving the query call from a for loop:

for instance in session.query(versions_table).filter(versions_table.c.version==Version):

and getting result by calling one of the table results:

 existingID = instance.id

(where id is the PK for the returning table)

What I can’t do is finding a way of firing the query at will, or as a result of a conditional statement, e.g.

if some conditions met:
 do query
 get / process result

I can only get the returned values by calling instance.fieldname

Could anyone point me to where I am going wrong, accepting that I’m not really 100% comfortable with how the SQLalchemy functions are setup/called.

What I want to do is along the lines of:

for instance in session.query(versions_table).filter(versions_table.c.version==Version):
 if instance.id == True:  #this is not correct
  print instance.id 
 else:
  print "no match"

fuller script:

from sqlalchemy import *
from sqlalchemy.orm import sessionmaker

engine = create_engine('mysql+mysqldb://u:p@localhost/sqlalchtest',
                   echo=False)

metadata = MetaData(bind=engine)
Session = sessionmaker(bind=engine)
versions_table = Table('versions', metadata, autoload=True)

def doVersionGet(sigfile_filename):
 tree = etree.parse(sigfile_filename)
 root = tree.getroot()
 attributes = root.attrib
 if 'DateCreated' in root.attrib:
  DateCreated = (attributes["DateCreated"])
 if 'Version' in root.attrib:
  Version = (attributes["Version"])
 doVersionPush(DateCreated,Version)

def doVersionPush(DateCreated,Version):
 session = Session() 
 for instance in session.query(versions_table).filter(versions_table.c.version==Version):
  existingID = instance.id 
  #this is not really what I want to do here any way, but this will fire the query every time

if __name__ == "__main__":
 path = "location\sub_sig_files"  ##home_subset for tests
 for (path, dirs, files) in os.walk(path):
  for file in files:
   sigfile_filename = str(path)+"\\"+str(file)
   doVersionGet(sigfile_filename) 
  • 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-02T10:19:36+00:00Added an answer on June 2, 2026 at 10:19 am

    You can execute the query with Query.all, which will execute the query and return the instances:

    instances = session.query(versions_table).filter(versions_table.c.version==Version).all()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on getting a python CGI script to work all day,
Following on from my previous question I have been working on getting my object
I have been working on getting my OSGi application to run outside eclipse. It
I'm working on getting better with OOP in Python and I've run into some
Ive been working on getting some of my code originally built on the mac
I have been working on getting $.ajax data compiled by using an php class
I have been working on getting a C++ IDE going on my 64-bit Windows
I'm working on getting capistrano to publish my PlayFramework app, but I'm having some
So working on getting my eclipse IDE going so I can develop my arduino
I am working on getting familiar with the Android SDK and I have having

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.