"Battleship" style game

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Feb 25 18:07:07 CET 2009

En Wed, 25 Feb 2009 14:50:18 -0200, Shawn Milochik <Shawn at milochik.com>  
> On Wed, Feb 25, 2009 at 11:38 AM, Marco Mariani <marco at sferacarta.com>  
> wrote:
>> Yes it's in Python alright, but it's not Pythonese yet. You could try
>> avoiding the getter/setter stuff, and camelCase method naming, things  
>> like
>> that, for a start.
> What do you mean avoiding the getter/setter stuff? If I understand
> correctly, you're saying to directly access the attributes, which I
> specifically want to avoid because I may want to enforce some rules
> (such as not changing a ship length after it's created).

I think Marco Mariani was suggesting something like this:

class Ship(object):

     def __init__(self, length):
         self._length = length

     def get_length(self):
         return self._length
     length = property(get_length)  # a read only property

Gabriel Genellina

More information about the Python-list mailing list