How to compare Debian package versions?

后端 未结 3 1160
鱼传尺愫
鱼传尺愫 2020-12-24 07:26

I looked at python-apt and python-debian, and they don\'t seem to have functionality to compare package versions. Do I have to write my own, or is

3条回答
  •  天涯浪人
    2020-12-24 07:47

    python-debian can do this too. It's used in an almost identical way to python-apt:

    from debian import debian_support 
    
    a = '1:1.3.10-0.3'
    b = '1.3.4-1'
    vc = debian_support.version_compare(a,b)
    if vc > 0:
        print('version a > version b')
    elif vc == 0:
        print('version a == version b')
    elif vc < 0:
        print('version a < version b')
    

    ouput:

    version a > version b
    

提交回复
热议问题