Re: Help cleaning up some code

2009-03-18 Thread Aahz
In article <814f91a3-faa4-4473-b28f-8e0e217fb...@f33g2000vbf.googlegroups.com>, odeits wrote: > >for row in rows: >ad = dict() Micro-optimization: ad = {} -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational sci

Re: Help cleaning up some code

2009-03-09 Thread odeits
On Mar 9, 1:06 am, Dennis Lee Bieber wrote: > On Sun, 8 Mar 2009 19:07:08 -0700 (PDT), odeits > declaimed the following in gmane.comp.python.general: > > > > > i get this error when running that query: > > > sqlite3.OperationalError: LIMIT clause should come after UNION not > > before > >        

Re: Help cleaning up some code

2009-03-08 Thread odeits
On Mar 8, 12:31 pm, Dennis Lee Bieber wrote: > On Sat, 7 Mar 2009 23:07:55 -0800 (PST), odeits > declaimed the following in gmane.comp.python.general: > > > > > > > For those of you who asked about the SQL the full function is here. > > The connection is to a sqlite database with the row_factory

Re: Help cleaning up some code

2009-03-08 Thread odeits
On Mar 8, 11:31 am, Dennis Lee Bieber wrote: > On Sat, 7 Mar 2009 23:07:55 -0800 (PST), odeits > declaimed the following in gmane.comp.python.general: > > > > > > > For those of you who asked about the SQL the full function is here. > > The connection is to a sqlite database with the row_factory

Re: Help cleaning up some code

2009-03-08 Thread odeits
On Mar 8, 4:48 am, "andrew cooke" wrote: > odeits wrote: > > On Mar 7, 1:07 pm, Scott David Daniels wrote: > >> odeits wrote: > >> > I am looking to clean up this code... any help is much appreciated. > >> > Note: It works just fine, I just think it could be done cleaner. > > >> > The result is a

Re: Help cleaning up some code

2009-03-08 Thread andrew cooke
andrew cooke wrote: > odeits wrote: >> On Mar 7, 1:07 pm, Scott David Daniels wrote: >>> odeits wrote: >>> > I am looking to clean up this code... any help is much appreciated. >>> > Note: It works just fine, I just think it could be done cleaner. >>> >>> > The result is a stack of dictionaries. t

Re: Help cleaning up some code

2009-03-08 Thread andrew cooke
odeits wrote: > On Mar 7, 1:07 pm, Scott David Daniels wrote: >> odeits wrote: >> > I am looking to clean up this code... any help is much appreciated. >> > Note: It works just fine, I just think it could be done cleaner. >> >> > The result is a stack of dictionaries. the query returns up to >> >

Re: Help cleaning up some code

2009-03-07 Thread odeits
On Mar 7, 10:58 pm, odeits wrote: > On Mar 7, 1:07 pm, Scott David Daniels wrote: > > > > > odeits wrote: > > > I am looking to clean up this code... any help is much appreciated. > > > Note: It works just fine, I just think it could be done cleaner. > > > > The result is a stack of dictionaries.

Re: Help cleaning up some code

2009-03-07 Thread odeits
On Mar 7, 1:07 pm, Scott David Daniels wrote: > odeits wrote: > > I am looking to clean up this code... any help is much appreciated. > > Note: It works just fine, I just think it could be done cleaner. > > > The result is a stack of dictionaries. the query returns up to > > STACK_SIZE ads for a u

Re: Help cleaning up some code

2009-03-07 Thread Scott David Daniels
odeits wrote: I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another con

Re: Help cleaning up some code

2009-03-07 Thread Martin P. Hellwig
Martin P. Hellwig wrote: while I am at it :-) if ignore == False: is probably cleaner when written if not ignore: -- mph -- http://mail.python.org/mailman/listinfo/python-list

Re: Help cleaning up some code

2009-03-07 Thread Martin P. Hellwig
Martin P. Hellwig wrote: def query_parser(QUERY, USER, STACK_SIZE): indexes = ['ni','adid','rundateid','rundate','city','state','status'] empty = 'None' stack = [] query_result = self.con.execute(QUERY,(USER,STACK_SIZE)).fetchall() ni = indexes[0] for row in query_resul

Re: Help cleaning up some code

2009-03-07 Thread Martin P. Hellwig
odeits wrote: I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another con

Re: Help cleaning up some code

2009-03-07 Thread andrew cooke
ah, yes, i didn't see that clearly. in this case it might be better to have: def copy(src, dst, name, null): value = src[name] dst[name] = null if value is None else value and then make it explicit in both cases: copy(row, ad, name, null=None) ... copy(row, ad, name, null='None') andrew Pa

Re: Help cleaning up some code

2009-03-07 Thread Gerard Flanagan
odeits wrote: I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another con

Re: Help cleaning up some code

2009-03-06 Thread Paul Rubin
"andrew cooke" writes: > def copy(src, dst, name, quote_none=False): > value = src[name] > dst[name] = 'None' if quote_none and value is None else value def copy(src, dst, name, default=None): value = src[name] dst[name] = value if value is not None else default > copy(row, ad, name,

Re: Help cleaning up some code

2009-03-06 Thread oscar deits
Thanks a lot! that copy function is a really neat trick! Yes the ni's are sorted, and yes the query SHOULD be the one to limit it to just one set of ni's; however, i am having trouble implementing that in sql. I am using sqlite3 atm and right now i have a very large select statment the gets me wha

Re: Help cleaning up some code

2009-03-06 Thread andrew cooke
odeits wrote: > I am looking to clean up this code... any help is much appreciated. > Note: It works just fine, I just think it could be done cleaner. > > The result is a stack of dictionaries. the query returns up to > STACK_SIZE ads for a user. The check which i think is very ugly is > putting an

Help cleaning up some code

2009-03-06 Thread odeits
I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another contraint saying th