Unsupported operand types in if/else list comprehension

George Sakkis george.sakkis at gmail.com
Sat Apr 11 16:52:56 EDT 2009


On Apr 11, 4:26 pm, Mike H <cmh.pyt... at gmail.com> wrote:

> George,
>
> I'd love to. Can you give me an idea of where to start looking? I've
> gone through a couple of books, and Googled a ton of websites. Maybe
> I'm just not using the right terms. My background is definitely not
> CompSci. But if you'd give me a suggestion of where to look, I'd
> appreciate it.

Sure; off the top of my head, check out SQLAlchemy [1], SQLObject [2]
or Storm [3]. SQLAlchemy is probably the most powerful but it has
arguably the steepest learning curve, so you might find it less
appealing initially. In any case, something as simple as an insert
should be trivial in all frameworks, e.g. in SQLAlchemy (if you don't
use the object-relational mapper) you can create an insert statement
as:

# create the statement (my_table: an sqlalchemy.Table)
>>> ins = my_table.insert().values(field1=value1, field2=value2, ..., fieldN=valueN)

# you can print to see the actual generated SQL
>>> str(ins)
'INSERT INTO my_table (field1, field2, ... fieldN) VALUES
(:field1, :field2, ... :fieldN)'

# execute it (conn: an active sqlachemy.engine.Connection)
>>> result = conn.execute(ins)

HTH,
George


[1] http://www.sqlalchemy.org/
[2] http://www.sqlobject.org/
[3] https://storm.canonical.com/

> On Sat, Apr 11, 2009 at 4:18 PM, George Sakkis <george.sak... at gmail.com> wrote:
> > On Apr 11, 3:03 pm, Mike H <cmh.pyt... at gmail.com> wrote:
>
> >> Can I not use the cursor.execute command to pass variables that aren't
> >> immediately next to each other? If so, is there a better way to go
> >> about solving this problem?
>
> > Yes, there is. Use one of the several production quality python SQL
> > toolkits built for exactly this purpose instead of putting together an
> > ad-hoc, informally-specified bug-ridden slow implementation of half of
> > their feature set.
>
> > George
> > --
> >http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list