python - version number comparison method optimization
阿神
阿神 2017-05-27 17:39:41
0
1
701

Recently I wrote a small method for the app version update function. It doesn’t feel very beautiful. How do you compare version numbers?

Version number adaptation format: pure numbers separated by .

def version_cmp(client_version, last_version):
    """
    func of compare version number
    :param str client_version:
    :param str last_version:
    :return:
    """
    client_version_list = client_version.split(".")
    last_version_list = last_version.split(".")
    try:
        for i in range(0, len(last_version_list)):
            if int(last_version_list[i]) > int(client_version_list[i]):
                return True
     except IndexError, e:
        return False
    return False
阿神
阿神

闭关修行中......

reply all(1)
洪涛

Your version number should only increase upwards, not decrease downwards. In fact, you only need to compare whether the values ​​are equal

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template