0

I have an example class:

class Example():

  def __init__(self, id, code, table):
    self.id = id
    self.code = code
    self.table = table

and three objects

a = Example(1,10,100)
b = Example(2,10,200)
c = Example(3,20,100)

What I would like to achieve is something like this:

s = [a,b,c]
x = sql(code = 10, s)  #x = (a,b)
x = sql(id = 3, s)  #x = (c,)
x = sql(table > 200, s)  #x = ()

I don't want to perform very complex queries but a suggestion of any approach is valuable as long as it is fast (That's why I don't use a filter function) and also avoids setting up an external database.

  • Sorry, asking for specific libraries is off-topic for Stack Overflow. You are looking for an *ORM*, an object relational mapper. Python has several, with [SQLAlchemy](https://www.sqlalchemy.org/) the most widely used, but do look at [other lists of Python ORMs](https://www.fullstackpython.com/object-relational-mappers-orms.html). – Martijn Pieters Jan 07 '20 at 12:50
  • This is not a question about ORMs! This is a question about filtering. The way the question is phrased is unfortunate (e.g. asking for a specific library), but I don't see this as off-topic. – asthasr Jan 07 '20 at 12:59
  • You can ask this in https://softwarerecs.stackexchange.com/ – Anis Smail Jan 07 '20 at 13:12
  • @asthasr: the way that this is worded *makes it off-topic*. But I see now that I misread this, so my list of recommendations doesn't apply. Oh well. I found a duplicate for the 'query Python objects' case. – Martijn Pieters Jan 07 '20 at 16:19

0 Answers0