can someone explain?

Jp Calderone exarkun at
Tue Feb 18 07:53:22 CET 2003

On Tue, Feb 18, 2003 at 01:19:33AM -0500, Mongryong wrote:
> On Mon, 2003-02-17 at 11:35, Pablo wrote:
> > def increase(val):
> >   val +=1
> As other's have explained, simple types like 'ints' are
> passed-by-value.  You'll need a wrapper class for pass as reference.

   This is wrong.

> > Why doesn't python let encapsulate attributes in classes? I can add
> > attribute to class whenever I want. I don't see any reason why.
> To enforce true OO encapsulate would probably mean more work for the
> Python VM -> hence, that makes Python slower.  Yes, it's true that you
> can add attributes to a class whenever you want to - however, I believe
> this feature had to be added to support inheritance.  The base class
> initializes 'self' with attributes, then the extended class may add new
> attributes to 'self'.  Now, if the Python VM were to forbid one from
> being able to add new attributes to 'self' outside of the '__init__'
> method, then the Python VM would have to do checks everytime 'self' is
> assigned a value.

  Encapsulation isn't the same as data hiding.  Python does not enforce data
hiding, but it allows as much or as little encapsulation as you like.

> Python in a way is very much like C++.  C++ has all these OO features,
> but it provides a 'back door' to support 'C' so that it can easily be
> integrated with legacy 'C' code and optimized at the 'hardware' level. 
> More importantly, C++ provides these escape routes for situations where
> there is no other 'clean (OO) way' to solve a problem - so, you just
> 'hack it' with a 'C' solution.  Python's no different.

  Unless you're referring to extension modules written in C (which I doubt),
this is wrong, too.

> In fact, because Java is so strict, it makes it difficult for non-OO
> programmers to use the language.

  It is a stretch to call Java an OO language at all.

> If you're a OO purist, Python has the 'essential' features for you.  If
> you're a procedural type programmer, Python has all the features you
> need as well.

  Python isn't "pure" in any real sense.  It's a pragmatist's language. 
You're right that it provides many features for many paradigms, though.

> > 
> > And the last question.
> > def f(a,L=[]):
> >   L.append(a)
> >   return L
> > 
> > >>f(1)
> > [1]
> > >>f(2)
> > [1,2]
> > >>f(3)
> > [1,2,3]
> > 
> > L is a default argument so every time when a function f is invoked, L
> > should be created and as a result f should return a list with only one
> > value.
> > Why doesn't it work that way?
> Default parameters are initialized at import time.  Don't know why it
> was done this way - maybe to support 'static method variables'?

  This is also wrong.  A thread on this topic recently appeared in this
group, with many good answers, as well as pointers to at least two FAQs
which give the correct answer to the question.


 up 9 days, 10:28, 3 users, load average: 0.00, 0.02, 0.03
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list