文章詳情頁
python - 版本號對比方法優(yōu)化
瀏覽:95日期:2022-06-30 08:47:22
問題描述
最近為app版本更新功能寫了個小方法,感覺不是很漂亮,請問大家版本號對比都是怎么做的呢
版本號適配格式:純數(shù)字用 . 分隔
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
問題解答
回答1:你的版本號應(yīng)該只會往上加,不會往下減,其實只要比對值是否相等即可
上一條:python - beautifulsoup獲取網(wǎng)頁內(nèi)容的問題下一條:python - 使用WhooshAlchemy報錯’function’ object has no attribute ’config’
相關(guān)文章:
1. 數(shù)據(jù)庫 - MySQL 單表500W+數(shù)據(jù),查詢超時,如何優(yōu)化呢?2. python - Django分頁和查詢參數(shù)的問題3. 求大神幫我看看是哪里寫錯了 感謝細心解答4. MySQL客戶端吃掉了SQL注解?5. android - Windows系統(tǒng)下運行react-native App時,報下面的錯誤?6. javascript - 圖片能在網(wǎng)站顯示,但控制臺仍舊報錯403 (Forbidden)7. php自學從哪里開始?8. mysql - AttributeError: ’module’ object has no attribute ’MatchType’9. javascript - JS設(shè)置Video視頻對象的currentTime時出現(xiàn)了問題,IE,Edge,火狐,都可以設(shè)置,反而chrom卻...10. phpstady在win10上運行
排行榜

熱門標簽