On 1/22/13 3:35 PM, Carey Gagnon wrote:
> John's suggestion above yours worked the easiest with my existing
> code. I some what understand your code but it appears to be missing the
> main thing I was trying to achieve which was to return the projectname and
> corresponding buildername combinations.
Yeah, I read your email too quickly. You'd just:
{{{
crec = crs.Record
for i in range(crs.RowCount):
crs.RowNumber = i
print crec.projectname, crec.buildername
}}}
> Your code seems to have changed
> what I already had working albeit with nicer formatting, not that I've
> tried the code. I see some what of the optimizations as well but don't
> understand it all. I've commented in your code.
>
>> crs = self.getTempCursor(""" ######
>> why triple quotes?
In Python, the triple ''' or """ specifies a multiline string. I think it's
nicer to
split up the SQL into multiple lines.
>> select builderfk,
>> projectname,
>> buildername
>> from projects
>> inner join builders
>> on builders.id = projects.builderfk
>> where projectname like ?""", (projectSearchName,)) ###### why triple
>> quotes after the ?
This ends the multiline string we started above.
>> names = [] ####### still ends up
>> being only the projectname without the builder anme
See above.
>> for i in range(crs.RowCount):
>> crs.RowNumber = i
>> names.append(crs.Record.projectname)
Here it would be something like:
names.append("%(projectname)s (%(buildername)s)" % crs.Record)
>> if names:
>> plural = ("is", "") ###### I like this...return the appropriate
>> *"is" *or *"are"*
Yep, it's the simplest way I've come up with (but you lose translation to other
languages).
>> if len(names) == 1:
>> plural = ("are", "s")
>> ret = "There %s %s project%s similar to %s already in the database,
>> as:\n" \
>> % (plural[0], len(names), plural[1], rec.projectname) #######
>> why plural[0] and plural[1] ?
plural[0] is equal to "is" for a single matching record or "are" for multiple.
Python
lists are 0-based not 1-based.
>> for name in sorted(names):
>> ret += " -> %s\n" % name
>> ret += "\nDo you want to add it anyway?"
>> return ret
>> }}}
>>
>> Thanks
No problem! Cheers!
Paul
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[email protected]