Sunday, June 12, 2016

Python: Sane version comparison with LooseVersion

 class Version(LooseVersion):  
 """Wrap distutils.version.LooseVersion with support for null versions."""  
    def __init__(self, version):  
      """Init."""  
      LooseVersion.__init__(self, str(version or 0))  
    def __cmp__(self, other):  
      """Compare."""  
      if not isinstance(other, LooseVersion):  
        other = Version(other)  
      return LooseVersion.__cmp__(self, other)  

No comments:

Post a Comment