Newbie Q: modifying SQL statements

Discussion in 'Python' started by Faber J. Fedor, Jan 11, 2008.

  1. 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?



    --

    Regards,

    Faber

    --
    This message has been scanned for viruses and
    dangerous content by MailScanner, and is
    believed to be clean.
    Faber J. Fedor, Jan 11, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    8
    Views:
    1,180
    mfmehdi
    Oct 20, 2006
  2. Harry George
    Replies:
    6
    Views:
    371
    Bart Nessux
    Feb 23, 2004
  3. Vince
    Replies:
    12
    Views:
    746
    Martin Gregorie
    Jan 21, 2008
  4. JT
    Replies:
    1
    Views:
    116
    Bob Barrows [MVP]
    Sep 27, 2005
  5. John Crichton
    Replies:
    6
    Views:
    259
    John Crichton
    Jul 12, 2010
Loading...

Share This Page