My python annoyances so far

Larry Bates larry.bates at websafe.com
Wed Apr 25 19:59:22 EDT 2007


flifus at gmail.com wrote:
> Hi all. I'm learning python these days. I'm going to use this thread
> to post, from time to time, my annoyances with python. I hope someone
> will clarify things to me where I have misunderstood them.
> 
> Annoyances:
> 
> 1. Underscores! What's the deal with that? Especially those double
> underscores. The best answer I read on this is that the double
> underscores denotes special methods that the interpreter may
> automatically use. For example, 4+4 get expanded by the interpreter to
> 4.__add__(4).
> 
> 2. There are modules, there are functions, and there are classes-
> methods! Wouldn't it have been easier had everything either been a
> function or a class method?
> 

1. Underscores.  __add__ is a special method that gets called when you
want to add two objects together. __init__ is the initalizer method
that gets called when a class is instantiated.  Special methods begin
and end with double underlines.  __variable is a class (or instance)
variable that shouldn't be manipulated outside the class that is
somewhat equivalent to private variables in other languages.  I say
somewhat because there is always a way to get to any variable, even
the double underline ones.  _variable is a class (or instance) variable
that is internal to the class an normally shouldn't depended upon
or manipulated from the outside unless the caller really knows what
they are doing.

2. Modules are collections of code.  They can be functions or classes.
Functions are functions, classes are classes, you need both in an
object oriented language.  Functions alone will not suffice.  If you
want to ignore classes at the beginning, please do so.

Suggestion: if you are just starting please accept that there is a
reason for Python being different from almost all "traditional" compiled
languages.  If you take some time you will come to understand and,
if you are like most, love the differences.  I've been creating a
cross-language COM object and after writing unit tests in VB, Delphi, and
Python I am once again reminded why I love Python.  I have more lines
of declarations in the Delphi version than in the Python program for some
tests.

-Larry



More information about the Python-list mailing list