Newbie Q: modifying SQL statements

F

Faber J. Fedor

Hi all,

I'm in the process of learning Python by writing a job queue program.
Nothing fancy, mind you, just read from a table, shell out to a program,
write back to the table.

I'm working off of the tutorial listed here (amongst many places):
http://www.devx.com/dbzone/Article/22093

In my Jobs class I have:

def __iter__(self):
"creates a data set, and returns an iterator (self)"
q = "select * from %s" % (self.name)
self._query(q)
return self # an Iterator is an object
# with a next() method

def next(self):
"returns the next item in the data set,
or tells Python to stop"
r = self.dbc.fetchone()
if not r:
raise StopIteration
return r

which works well, but what if I want to modify the __iter__ query? I
want to be able to do something like this (and I know this is not the
right syntax but you'll get my drift):


for job in jobs: print job # which the above code does
for job in jobs("status = running"): print job
for job in jobs("jobid = 4"): print job

What's the pythonic way of doing this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top