Is my thinking Pythonic?

Hussein B hubaghdadi at
Thu Aug 21 14:21:23 CEST 2008

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