Does Python really follow its philosophy of "Readability counts"?

James Mills prologic at shortcircuit.net.au
Wed Jan 14 04:39:30 CET 2009


On Wed, Jan 14, 2009 at 1:31 PM, r <rt8396 at gmail.com> wrote:
>> public = no leading underscore
>> private = one leading underscore
>> protected = two leading underscores
>>
>> Python uses encapsulation by convention rather than by enforcement.
>
> Very well said Terry!
>
> I like that python does not force me to do "everything" but does force
> things like parenthesis in a function/method call whether or not an
> argument is required/expected. This makes for very readable code.
> Visual parsing a Python file is very easy on the eyes due to this fact
> -- Thanks Guido! We do not need to add three new keywords when there
> is an accepted Pythonic way to handle public/private/protected

Agreed. Furthermore there very few cases where you need
to distinguish between whether an object's attribute is public
or private or even protected.

Consider the following two pieces of code and tell me
which is more Pythonic:

class A(object):

   def __init__(self):
      self.x = None

   def setX(self, v):
      self.x = v

   def getX(self):
      return self.x

----------------------------------------

class A(object):

   def __init__(self):
      self.x = None

I'll give you a hint ... It's the simpler one :)

cheers
James



More information about the Python-list mailing list