Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Chris Rebert wrote: > On Fri, May 21, 2010 at 1:09 PM, Alex Hall wrote: >> On 5/21/10, Ethan Furman wrote: >>> Alex Hall wrote: On 5/20/10, alex23 wrote: I have since updated each ship's __init__ to accept all the arguments that Craft accepts so that I can suppor

Re: optional argument to a subclass of a class

2010-05-21 Thread Chris Rebert
On Fri, May 21, 2010 at 1:09 PM, Alex Hall wrote: > On 5/21/10, Ethan Furman wrote: >> Alex Hall wrote: >>> On 5/20/10, alex23 wrote: >>> I have since updated each ship's >>> __init__ to accept all the arguments that Craft accepts so that I can >>> support all optional arguments, >> >> Ick.  Now

Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Ethan Furman wrote: > Alex Hall wrote: >> On 5/20/10, alex23 wrote: >> I have since updated each ship's >> __init__ to accept all the arguments that Craft accepts so that I can >> support all optional arguments, > > Ick. Now you'll have to change several things if you make one change

Re: optional argument to a subclass of a class

2010-05-21 Thread Ethan Furman
Alex Hall wrote: On 5/20/10, alex23 wrote: I have since updated each ship's __init__ to accept all the arguments that Craft accepts so that I can support all optional arguments, Ick. Now you'll have to change several things if you make one change to the Craft class. Better to do it this wa

Re: optional argument to a subclass of a class

2010-05-21 Thread Chris Rebert
On Fri, May 21, 2010 at 11:49 AM, Chris Rebert wrote: > On Fri, May 21, 2010 at 11:38 AM, Alex Hall wrote: >> On 5/21/10, Christian Heimes wrote: >>> Am 21.05.2010 04:56, schrieb Alex Hall: Hi all, I am now trying to allow my classes, all of which subclass a single class (if that

Re: optional argument to a subclass of a class

2010-05-21 Thread Peter Otten
Alex Hall wrote: > On 5/21/10, Christian Heimes wrote: >> Am 21.05.2010 04:56, schrieb Alex Hall: >>> Hi all, >>> I am now trying to allow my classes, all of which subclass a single >>> class (if that is the term), to provide optional arguments. Here is >>> some of my code: >>> >>> class Craft():

Re: optional argument to a subclass of a class

2010-05-21 Thread Chris Rebert
On Fri, May 21, 2010 at 11:38 AM, Alex Hall wrote: > On 5/21/10, Christian Heimes wrote: >> Am 21.05.2010 04:56, schrieb Alex Hall: >>> Hi all, >>> I am now trying to allow my classes, all of which subclass a single >>> class (if that is the term), to provide optional arguments. Here is >>> some

Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Christian Heimes wrote: > Am 21.05.2010 04:56, schrieb Alex Hall: >> Hi all, >> I am now trying to allow my classes, all of which subclass a single >> class (if that is the term), to provide optional arguments. Here is >> some of my code: >> >> class Craft(): >> def __init__(self, >>

Re: optional argument to a subclass of a class

2010-05-21 Thread Christian Heimes
Am 21.05.2010 04:56, schrieb Alex Hall: Hi all, I am now trying to allow my classes, all of which subclass a single class (if that is the term), to provide optional arguments. Here is some of my code: class Craft(): def __init__(self, name, isAircraft=False, id=helpers.id(), hits=0,

Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Terry Reedy wrote: > On 5/20/2010 10:56 PM, Alex Hall wrote: > > A couple of style comments for you to consider. > >> class Craft(): >> def __init__(self, >> name, >> isAircraft=False, >> id=helpers.id(), >> hits=0, >> weapons=[]): > > Not indenting lines after def makes th

Re: optional argument to a subclass of a class

2010-05-21 Thread Terry Reedy
On 5/20/2010 10:56 PM, Alex Hall wrote: A couple of style comments for you to consider. class Craft(): def __init__(self, name, isAircraft=False, id=helpers.id(), hits=0, weapons=[]): Not indenting lines after def makes the code harder to read for me, and, I expect, many others h

Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Peter Otten <__pete...@web.de> wrote: > Alex Hall wrote: > >> Hi all, >> I am now trying to allow my classes, all of which subclass a single >> class (if that is the term), to provide optional arguments. Here is >> some of my code: >> >> class Craft(): >> def __init__(self, >> name, >

Re: optional argument to a subclass of a class

2010-05-21 Thread Peter Otten
Alex Hall wrote: > Hi all, > I am now trying to allow my classes, all of which subclass a single > class (if that is the term), to provide optional arguments. Here is > some of my code: > > class Craft(): > def __init__(self, > name, > isAircraft=False, > id=helpers.id(), > hits=0, > weapon

Re: optional argument to a subclass of a class

2010-05-21 Thread Steven D'Aprano
On Thu, 20 May 2010 23:35:01 -0400, Alex Hall wrote: >> You overrode the __init__method from the superclass. > > I know, I thought I had to in order to make all of Craft's attribs > available to the Battleship. Is that not the case? No, the opposite in fact. One of the basic features of objects

Re: optional argument to a subclass of a class

2010-05-20 Thread Alex Hall
On 5/20/10, alex23 wrote: > Patrick Maupin wrote: >> One thing you can do is in battleship, you can accept additional >> keyword arguments: >> >> def __init__(self, name, ..., **kw): >> >> Then you could invoke the superclass's init: >> >> Craft.__init__(self, name, **kw) > > _All_ of whi

Re: optional argument to a subclass of a class

2010-05-20 Thread Patrick Maupin
On May 20, 10:35 pm, Alex Hall wrote: > So how do I get at anything inside **kw? Is it a list? It's a dictionary. Use *args for a list. (As with self, the name is whatever you want to use, but some sort of consistency is nice.) One of the cool things about Python is how easy it is to play at

Re: optional argument to a subclass of a class

2010-05-20 Thread alex23
Patrick Maupin wrote: > One thing you can do is in battleship, you can accept additional > keyword arguments: > >     def __init__(self, name, ..., **kw): > > Then you could invoke the superclass's init: > >     Craft.__init__(self, name, **kw) _All_ of which is covered in the tutorial. At what p

Re: optional argument to a subclass of a class

2010-05-20 Thread Alex Hall
On 5/20/10, Patrick Maupin wrote: > On May 20, 9:56 pm, Alex Hall wrote: >> Hi all, >> I am now trying to allow my classes, all of which subclass a single >> class (if that is the term), to provide optional arguments. Here is >> some of my code: >> >> class Craft(): >> def __init__(self, >> nam

Re: optional argument to a subclass of a class

2010-05-20 Thread Patrick Maupin
On May 20, 9:56 pm, Alex Hall wrote: > Hi all, > I am now trying to allow my classes, all of which subclass a single > class (if that is the term), to provide optional arguments. Here is > some of my code: > > class Craft(): >  def __init__(self, >  name, >  isAircraft=False, >  id=helpers.id(), >

optional argument to a subclass of a class

2010-05-20 Thread Alex Hall
Hi all, I am now trying to allow my classes, all of which subclass a single class (if that is the term), to provide optional arguments. Here is some of my code: class Craft(): def __init__(self, name, isAircraft=False, id=helpers.id(), hits=0, weapons=[]): self.name=name self.id=id sel