jonathan.beckett wrote:
I'm just finding it a bit weird that some of the built in functions are
> static, rather than methods of objects (such as len() being used to
> find the length of a list).
Another explanation here:
http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality
On 28 Dec 2006 08:40:02 -0800, "jonathan.beckett"
<[EMAIL PROTECTED]> wrote:
>Hi all,
>
>Question 2...
>What is the correct way of looping through a list object in a class via
>a method of it?
Without peeking at any of the other responses, here is what I came up
with. I hope it helps...
class G
"jonathan.beckett" <[EMAIL PROTECTED]> wrote:
> I'm just finding it a bit weird that some of the built in functions are
> static, rather than methods of objects (such as len() being used to
> find the length of a list).
When it comes down to it, its a design decision, so neither right nor wrong
jonathan.beckett wrote:
>> ...
>>class Battleship(object):
>>...
>>def getShellsLeft(self):
>>numShells = 0
>>for aGun in self.guns:
>>numShells += aGun.shells
>>return numShells
>>...
>
> Excellent example - once upo
> Too many misconceptions here (I changed to a more PEP-8 style naming):
>
>class Gun(object):
>def __init__(self):
>self.shells = 10
>
>class Battleship(object):
>def __init__(self):
>self.guns = [Gun(), Gun()]
>
>def getShellsLeft(self):
>
jonathan.beckett wrote:
> Hi all,
>
> While working on support at work, I have been picking away at Python -
> because I think it could be a valuable scripting tool for building
> utilities from. I have been reading the python.org tutorials, and
> playing around with some basic code, but I have en
> > I normally work with PHP, C#, Javascript, and the odd bit of C++,
>
> Do any of them call functions w/o parens?
That's a really good point :)
--
http://mail.python.org/mailman/listinfo/python-list
On 2006-12-28, jonathan.beckett <[EMAIL PROTECTED]> wrote:
> I'm just finding it a bit weird that some of the built in functions are
> static, rather than methods of objects (such as len() being used to
> find the length of a list).
Well, they actually are methods of objects (at least they are
no
On 2006-12-28, jonathan.beckett <[EMAIL PROTECTED]> wrote:
>> > Given the code below, why does the count method return what it does?
>> > How *should* you call the count method?
>> > a = []
>> > a.append(1)
>> > print a.count
>>
>> print a.count().
Which will cause an exception, BTW, since
Hi Grant, thanks for the code snippets - made total sense.
On the evidence of the last couple of hours, Python is still feeling
very alien, but I'm starting to get my head around it.
I'm just finding it a bit weird that some of the built in functions are
static, rather than methods of objects (su
Chris Mellon wrote:
> On 28 Dec 2006 08:40:02 -0800, jonathan.beckett
> <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > While working on support at work, I have been picking away at Python -
> > because I think it could be a valuable scripting tool for building
> > utilities from. I have been readi
On 28 Dec 2006 08:40:02 -0800, jonathan.beckett
<[EMAIL PROTECTED]> wrote:
> Hi all,
>
> While working on support at work, I have been picking away at Python -
> because I think it could be a valuable scripting tool for building
> utilities from. I have been reading the python.org tutorials, and
>
On 2006-12-28, jonathan.beckett <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> While working on support at work, I have been picking away at Python -
> because I think it could be a valuable scripting tool for building
> utilities from. I have been reading the python.org tutorials, and
> playing around w
Hi all,
While working on support at work, I have been picking away at Python -
because I think it could be a valuable scripting tool for building
utilities from. I have been reading the python.org tutorials, and
playing around with some basic code, but I have ended up with a few
questions that pro
14 matches
Mail list logo