|
From: Bryan M. <bmu...@gm...> - 2005-02-22 04:19:41
|
It look like you have to be careful to hit Reply All to reply to the
list with these sourceforge mailing lists, I just noticed.
On Mon, 21 Feb 2005 09:56:59 -0700, Mike Trionfo <mik...@gm...> wrote:
> Overall it looks pretty good, but what is with the triple double-quotes?
That's how you do multi-line strings in Python. I guess since it's
whitespace sensitive there has to be special syntax for that.
The triple quoted strings just after function defs are docstrings,
kinda like javadoc, I hear. There is something called pydoc that uses
them.
>
> A couple of suggestions:
>
> Line 81:
> If you want to assure that you only get one record back from the
> troops table with that name then you can put a unique key constraint
> on the field or you can do LIMIT 1 at then end of the query... or you
> can add other filters to make sure you will always only get back one
> record.
I've never heard of a unique key constraint, I need a good SQL
reference. There are probably more than just the troop names we want
unique, so that's good to know.
> Line 90:
> Instead of fetching x records with just an id in it from scouts in the
> database so that you can go back and fetch the firstname, lastname,
> birthdate for each of those ids, just SELECT * FROM scouts WHERE
> troop_id = some_id. Then loop on those records that you get back and
> you will have everything you need with one query.
>
> If you did it the way you did to save speed, then don't worry about
> that. Unless you have a lot of text fields in a record set, then
> selecting anything other than * is miniscully faster.
No, looking back at that, I'm not sure why I did it the way I did.
Thanks for pointing this out.
>
> - You may want to get into the habit of writing your SQL keywords in all caps.
I've noticed that seems to be the agreed upon standard. It seems like
a pain, but if that's what everyone else does I guess I could to.
> - You don't have to encapsulate your filter values in your WHERE
> clause in single quotes if you filtering by an integer. You can just
> use the value directly. You may want to use %d for the ints if python
> supports it
I noticed that at one point, but didn't feel like going back and
changing anything. Python does do %d, so maybe we can change them.
> Do you know if you can call class methods statically in python?
You are making me re-read the advanced object oriented section of
Learning Python, but I guess I'll forgive you :-)
You can have instance, static, or class methods in Python classes. I
think the static class methods are what you are talking about. It
gives the classic example of keeping track of the number of instances
of a class inside the class itself.
class Spam:
numInstances = 0
def __init__(self):
Spam.numInstances += 1
def printNumInstances():
print "Number of Instances:", Spam.numInstances
printNumInstances = staticmethod( printNumInstances )
Then you can call it either like Spam.printNumInstances() or through
an instance:
a = Spam()
a.printNumInstances()
And it looks like you can do a lot of other crazy stuff with classes. Fun fun.
Bryan
|