Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: Newbie Q: modifying SQL statements
Faber J. Fedor
1/11/2008 11:12:00 PM
On 10/01/08 22:53 -0500, Mike Meyer wrote:
> Personally, I think it would be more pythonic to not try and use two
> different APIs to walk the list of jobs (... One Way To Do it):
>
> def __call__(self, where=None):
> q = "select * from %s" % (self.name,) + ("" if not where else (" where %s" % where))
Does this '("" if not where...' syntax actually work? I couldn't get it to
compile and I couldn't find any examples of such syntax (but you can't
expect googling for 'if not' to be too successful). I ended up
changing that line to:
q = "select * from %s" % (self.name,)
if where: q += "where %s" %where
> for r in self.dbc.iterresults() # I assume it has something like this
I don't think it does, if I read
http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQ...
correctly.
--
Regards,
Faber Fedor
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
2 Answers
Hrvoje Niksic
1/11/2008 11:24:00 PM
0
"Faber J. Fedor" <faber@linuxnj.com> writes:
> On 10/01/08 22:53 -0500, Mike Meyer wrote:
>> Personally, I think it would be more pythonic to not try and use two
>> different APIs to walk the list of jobs (... One Way To Do it):
>>
>> def __call__(self, where=None):
>> q = "select * from %s" % (self.name,) + ("" if not where else (" where %s" % where))
>
> Does this '("" if not where...' syntax actually work?
http://docs.python.org/whatsnew/pe...
Faber J. Fedor
1/12/2008 3:36:00 AM
0
On 12/01/08 00:23 +0100, Hrvoje Niksic wrote:
> "Faber J. Fedor" <faber@linuxnj.com> writes:
> > Does this '("" if not where...' syntax actually work?
>
>
http://docs.python.org/whatsnew/pe...
C'mon! I'm in Day Two of learning Python. You can't expect me to be
reading "What's New" docs already! :-)
I did find it interesting that the page mentioned said "Guido van Rossum
eventually chose a surprising syntax:". When I first saw the construct
I thought "Oh, they borrowed that from Perl". :-) (Although you can't do the
else part in Perl, it is a natural extension, IMO.)
--
Regards,
Faber Fedor
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Newbie Q: modifying SQL statements
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password