title: Pythonic way of rewrite Java code in Python
body: <p>I have to write a library in python which was written in Java before. Coming from a Java background python is giving me a little difficult time. I am stuck with choosing the right pythonic way of doing something..</p>
  
  <p>So, My java code is something like: </p>
  
  <pre><code>import java.util.Collection;
  
  public abstract class MyEnumBaseClass
  {
      protected int    value;
      protected String description = null;
  
      protected MyEnumBaseClass(int iValue, String iDescription)
      {
          value = iValue;
          description = iDescription;
      }
  
      public int getValue()
      {
          return value;
      }
  
      public String getDescription()
      {
          return description;
      }
  
      protected static MyEnumBaseClass getEnum(Collection&lt;MyEnumBaseClass&gt; iter, int value)
      {
          for (MyEnumBaseClass enumObj : iter)
          {
              if (enumObj.getValue() == value)
              {
                  return enumObj;
              }
          }
          return null;
      }
  }
  
  
  
  import java.util.ArrayList;
  import java.util.Collection;
  
  public class MyEnumClass extends MyEnumBaseClass
  {
      private final static Collection&lt;MyEnumBaseClass&gt; enumList   = new ArrayList&lt;MyEnumBaseClass&gt;();
  
      public final static int                          ERROR1     = 1;
      public final static int                          ERROR2     = 2;
      public final static int                          ERROR3     = 3;
      public final static int                          ERROR4     = 4;
  
      public final static MyEnumClass                  ErrorEnum1 = new MyEnumClass(ERROR1, "ERROR1");
      public final static MyEnumClass                  ErrorEnum2 = new MyEnumClass(ERROR2, "ERROR1");
      public final static MyEnumClass                  ErrorEnum3 = new MyEnumClass(ERROR3, "ERROR1");
      public final static MyEnumClass                  ErrorEnum4 = new MyEnumClass(ERROR4, "ERROR1");
  
      protected MyEnumClass(int iValue, String iDescription)
      {
          super(iValue, iDescription);
      }
  
      public static int getCount()
      {
          return enumList.size();
      }
  
      public static Collection&lt;MyEnumBaseClass&gt; getList()
      {
          return enumList;
      }
  
      public static MyEnumBaseClass getEnum(int value)
      {
          return getEnum(enumList, value);
      }
  }
  </code></pre>
  
  <p>I want to write something this in python. I understand both languages are totally different. I don't want to replicate exact code but I want to write something in python which give me the functionality Java code is giving.</p>
  
  <p>So I came up with something like:</p>
  
  <pre><code># MODULE MYENUMBASECLASS:::
  
  class MyEnumBaseClass(object):
  
      def __init__(self, iValue, iDescription, ui = None):
          self._value = iValue
          self._description = iDescription
  
      def getValue(self):
          return self._value
  
      def getDescription(self):
          return self._description
  
      @classmethod
      def getEnum(cls, value, itr):
          for enumObj in itr:
              if enumObj.getValue() == value:
                  return enumObj
          return None
  
  
  # MODULE: ENUMS:::
  from MyEnumBaseClass import MyEnumBaseClass
  
  __all__ = ["MyEnumClassConstants", "MyEnumClass", "MyEnums"]
  _enumList = []
  
  class MyEnumClassConstants(object):
      ERROR1 = 1
      ERROR2 = 2
      ERROR3 = 3
      ERROR4 = 4
  
  class MyEnumClass(MyEnumBaseClass):
      def __init__(self, v, d, ui):
          global _enumList
          super(MyEnumClass, self).__init__(v, d, ui)
          _enumList.append(self)
  
      @staticmethod
      def getCount():
          return len(_enumList)
  
      @staticmethod
      def getList():
          return _enumList
  
      @classmethod
      def getEmum(cls, value, itr = None):
          return super(MyEnumClass, cls).getEnum(value, _enumList)
  
  
  class MyEnums(object):
      ErrorEnum1 = MyEnumClass(MyEnumClassConstants.ERROR1, "ERROR1");
      ErrorEnum2 = MyEnumClass(MyEnumClassConstants.ERROR2, "ERROR2");
      ErrorEnum3 = MyEnumClass(MyEnumClassConstants.ERROR3, "ERROR3");
      ErrorEnum4 = MyEnumClass(MyEnumClassConstants.ERROR4, "ERROR4");
  </code></pre>
  
  <p>I Want to know:</p>
  
  <ol>
  <li><p>Is it the correct pythonic way of doing it?</p></li>
  <li><p>I wanted to move the ErrorEnum1,2,3,4 and constants out of the MyEnums class as a module variable. But that way I will have a long list in my <strong>all</strong> variable. also I have a risk of variable name clash when I will import Enums module in other module (some other Enums2 module may also have ErrorEnum1,2,3.. But that is not a big problem. We can always use Enums.ErrorEnum1 and Enums2.ErrorEnum1). Am I thinking right?</p></li>
  <li><p>I know this is not perfect (my first python code ever). So I invite you guys for giving me ideas. </p></li>
  </ol>
  
  <p>Thanks  </p>