Is my thinking Pythonic?

Hussein B hubaghdadi at gmail.com
Thu Aug 21 08:21:23 EDT 2008


Hey,
Well, as you all know by now, I'm learning Python :)
One thing that is annoying my is the OOP in Python.
Consider this code in Java:
--
public class Car {
  private int speed;
  private String brand;
  // setters & getters
}
--
With one look at the top of the class, you  can know that each
instance has two instance variables (speed & brand).
I tried to transform in into Python:
--
class Car:
  def setspeed(self, speed):
     self.speed = speed
  def setbrand(self, brand):
     self.brand = brand
--
If you have a huge class, you can't figure the instance variables of
each object.
So, I created this constructor:
--
def __init__(self):
  self.speed = None
  self.brand = None
--
This way, I can figure the instance variables by just reading the
__init__ method.
What do you think of my approach? is it considered Pythonic?
Any suggestions?
Thank you all.



More information about the Python-list mailing list