"David Merrick" wrote
Is it possible too have
crit1 = Critter("Dave")
crit2 = Critter("Sweetie")
farm = [crit1,crit2] #List#
and then be able to use Critters methods on farm?
No, Marc has already answered that.
class Critter(object):
"""A virtual pet"""
def __init__(self, name, hu
On Sun, Jun 26, 2011 at 7:12 PM, David Merrick wrote:
> Is it possible too have
>
> crit1 = Critter("Dave")
> crit2 = Critter("Sweetie")
> farm = [crit1,crit2] #List#
>
> and then be able to use Critters methods on farm?
>
> No. farm is a list, and lists don't inherit the methods of the objects
Is it possible too have
crit1 = Critter("Dave")
crit2 = Critter("Sweetie")
farm = [crit1,crit2] #List#
and then be able to use Critters methods on farm?
# Critter Caretaker
# A virtual pet to care for
class Critter(object):
"""A virtual pet"""
def __init__(self, name, hunger = 0, bore
"David Merrick" wrote
Can someone show me how to code this correctly please?
We've been doing that but you are still making
some very basic mistakes which reflect a deep
misunderastanding of what you are doing. You
really should take several steps back and review
the use of variables and fun
"michael scott" wrote
you are using python 3 by your print statements, so I
don't think you need the int() around your input,
Yes he does because in Python 3 input is the same as raw_input
in Python 2
even in python.2x input() was safe for numbers I believe
(the whole list will rip my
t: Wednesday, June 22, 2011 6:48 PM
Subject: Re: [Tutor] Class methods
David,
2011/6/22 David Merrick :
> # listen to your critter
> elif choice == "1":
> for critter in farmlet:
> farmlet.talk()
You want to call .talk() on your "
David,
2011/6/22 David Merrick :
> # listen to your critter
> elif choice == "1":
> for critter in farmlet:
> farmlet.talk()
You want to call .talk() on your "critter" instance which has the
.talk() method, not on farmlet (which is a list as the error m
Can someone show me how to code this correctly please?
# Critter Caretaker
# A virtual pet to care for
class Critter(object):
"""A virtual pet"""
def __init__(self, name, hunger = 0, boredom = 0):
self.name = name
self.hunger = hunger
self.boredom = boredom
#
"David Merrick" wrote
class Critter(object):
def __init__(self, name, hunger = 0, boredom = 0):
def __pass_time(self):
def __str__(self):
@property
def mood(self):
def talk(self):
def eat(self):
def play(self):
class Farm(Critter):
I still don't think a Farm is a typ
# Critter Caretaker
# A virtual pet to care for
class Critter(object):
"""A virtual pet"""
def __init__(self, name, hunger = 0, boredom = 0):
self.name = name
self.hunger = hunger
self.boredom = boredom
# __ denotes private method
def __pass_time(self):
On 5/30/10, Alan Gauld wrote:
> "Alex Hall" wrote
>
>> that it will hit. I would like to not instantiate a Harpoon object,
>> just call the Harpoon's getImpactCoords method and pass it the
>> required arguments. Is this possible?
>
> Others have pointed out that
> a) This is possible using static
"Alex Hall" wrote
that it will hit. I would like to not instantiate a Harpoon object,
just call the Harpoon's getImpactCoords method and pass it the
required arguments. Is this possible?
Others have pointed out that
a) This is possible using staticmetjhod or classmetjod decorators and
b) it s
Hi Alex, thanks for the response, please see below.
On 30/05/2010 02:50, Alex Hall wrote:
On 5/29/10, Mark Lawrence wrote:
On 29/05/2010 20:49, Alex Hall wrote:
Hi all,
In Battleship, I have a weapons.py file, currently with just one
missile type (a Harpoon anti-ship missile). This Harpoon cl
On Sun, 30 May 2010 05:49:45 am Alex Hall wrote:
> Hi all,
> In Battleship, I have a weapons.py file, currently with just one
> missile type (a Harpoon anti-ship missile). This Harpoon class
> defines a getImpactCoords method, which returns all coordinates on
> the map that it will hit. I would lik
On 5/29/10, Mark Lawrence wrote:
> On 29/05/2010 20:49, Alex Hall wrote:
>> Hi all,
>> In Battleship, I have a weapons.py file, currently with just one
>> missile type (a Harpoon anti-ship missile). This Harpoon class defines
>> a getImpactCoords method, which returns all coordinates on the map
>>
On 29/05/2010 20:49, Alex Hall wrote:
Hi all,
In Battleship, I have a weapons.py file, currently with just one
missile type (a Harpoon anti-ship missile). This Harpoon class defines
a getImpactCoords method, which returns all coordinates on the map
that it will hit. I would like to not instantiat
On 05/30/10 05:49, Alex Hall wrote:
> Hi all,
> In Battleship, I have a weapons.py file, currently with just one
> missile type (a Harpoon anti-ship missile). This Harpoon class defines
> a getImpactCoords method, which returns all coordinates on the map
> that it will hit. I would like to not inst
Hi all,
In Battleship, I have a weapons.py file, currently with just one
missile type (a Harpoon anti-ship missile). This Harpoon class defines
a getImpactCoords method, which returns all coordinates on the map
that it will hit. I would like to not instantiate a Harpoon object,
just call the Harpoo
On Fri, 28 May 2010 07:42:30 am Alex Hall wrote:
> Thanks for all the explanations, everyone. This does make sense, and
> I am now using the
> if(arg==None): arg=self.arg
> idea. It only adds a couple lines, and is, if anything, more explicit
> than what I was doing before.
You should use "if arg
Thanks for all the explanations, everyone. This does make sense, and I
am now using the
if(arg==None): arg=self.arg
idea. It only adds a couple lines, and is, if anything, more explicit
than what I was doing before.
On 5/27/10, Mark Lawrence wrote:
> On 23/05/2010 20:40, Alex Hall wrote:
>> Hello
On 23/05/2010 20:40, Alex Hall wrote:
Hello all,
I know Python reasonably well, but I still run into basic questions
which those over on the other python list request I post here instead.
I figure this would be one of them:
Why would this not work:
class c(object):
def __init__(self, arg1, arg
On Sun, 23 May 2010 15:40:13 -0400
Alex Hall wrote:
> Hello all,
> I know Python reasonably well, but I still run into basic questions
> which those over on the other python list request I post here instead.
> I figure this would be one of them:
> Why would this not work:
>
> class c(object):
>
Hey Alex,
What's happening is that you're still in "defining functions" mode on the
line
def doSomething(self, arg3=self.arg1):
self, which is really nothing more than a parameter being passed in (special
parameter, but a parameter none the less) hasn't been assigned a value yet.
Imagine this f
"Alex Hall" wrote
class c(object):
def __init__(self, arg1, arg2):
self.arg1=arg1
self.arg2=arg2
def doSomething(self, arg3=self.arg1):
...
The above results in an error that "name 'self' is not defined". Why
can I not set the default values of a method's arguments to class
vars
like th
Hello all,
I know Python reasonably well, but I still run into basic questions
which those over on the other python list request I post here instead.
I figure this would be one of them:
Why would this not work:
class c(object):
def __init__(self, arg1, arg2):
self.arg1=arg1
self.arg2=arg2
d
thomas coopman wrote:
> On Sat, 10 Feb 2007 09:04:15 -0500
> Kent Johnson <[EMAIL PROTECTED]> wrote:
>> If you do want to keep FooList then you should call
>> SortedList.__init__() to set the compare function.
>> SortedList.__init__ is an unbound function so you call it like this:
>>SortedLis
On Sat, 10 Feb 2007 09:04:15 -0500
Kent Johnson <[EMAIL PROTECTED]> wrote:
> thomas coopman wrote:
> >
> > also,
> > Is it better to use super in FooList? and how should I use it then?
>
> Actually I would say that FooList is not pulling its weight.
> SortedList already allows specialization by
thomas coopman wrote:
> Thank you for the explanation of bound and unbound methods.
> I understand that it is more common to use a bound method, but I don't
> think that I can use this because at the time I save the method, I don't
> know anything about the instances.
That would be an appropriate
On Sat, 10 Feb 2007 07:55:54 -0500
Kent Johnson <[EMAIL PROTECTED]> wrote:
> thomas coopman wrote:
> > Hi,
> >
> > I want to do something like this, don't know how to properly
> > explain it, so I just give you some example code
> >
> class Foo(object):
> def method(self, arg):
>
Hi Thomas,
thomas coopman wrote:
> I want to execute the class method given as argument,
> but this obvious doesn't work, but I don't know how to
> get it work,
Pass the method reference of the class as argument, like this:
>>> class A(object):
... def __init__(self, x): self.x = x
...
thomas coopman wrote:
> Hi,
>
> I want to do something like this, don't know how to properly explain it,
> so I just give you some example code
>
class Foo(object):
def method(self, arg):
print arg
>
def doSomething(object, func):
object.func("test")
>
On Sat, 10 Feb 2007 22:10:52 +1000
Jonathan McManus <[EMAIL PROTECTED]> wrote:
> It's pretty easy to make this work, actually. The issue is in the
> "doSomething" method.
>
> > >>>class Foo(object):
> > >>> def method(self, arg):
> > >>> print arg
> >
> > >>>def doSomething(object, func)
Hi,
I want to do something like this, don't know how to properly explain it,
so I just give you some example code
>>>class Foo(object):
>>> def method(self, arg):
>>> print arg
>>>def doSomething(object, func):
>>> object.func("test")
>>>object = Foo()
>>>doSomething(object,
33 matches
Mail list logo