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
Your version number should only increase upwards, not decrease downwards. In fact, you only need to compare whether the values are equal