python - Using a variable on sqlalchemy query filter -


its possible use variables on filters?

my actual code:

import sqlalchemy sqlalchemy import table, metadata, column, integer, string sqlalchemy.orm import sessionmaker sqlalchemy.ext.declarative import declarative_base   location = 'localhost' engine_str = 'mysql+mysqlconnector://xxx:xxx@xxx/xxx'.format(location) engine = sqlalchemy.create_engine(engine_str, echo=false) session = sessionmaker(bind=engine) connection = engine.connect() session = session(bind=connection) metadata = metadata() base = declarative_base()  class services(base):     """     service details on database     """     __tablename__ = 'some_table'     id = column(integer, primary_key=true)     color= column(string)     shape= column(string)      def __repr__(self):         return self.shape 

this works:

for c in session.query(services).filter(services.name.in_(['blue','red'])):     print(c) 

result:

    circle, square 

but using avariable, returns:

services = ('blue','red') c in session.query(services).filter(services.name.in_([services])):     print(c) 

result:

mysql.connector.errors.programmingerror: failed processing pyformat-parameters; 'mysqlconverter' object has no attribute '_tuple_to_mysql' 

thanks in advance!

services already sequence, no need wrap in list:

for c in session.query(services).filter(services.name.in_(services)): 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -