dictionary.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:tools 作者: freedict 项目源码 文件源码
def extract_version(string):
    """Try to extract a version from the given string and feed it into
    distutils.version.StrictVersion, which is returned. If no version could be
    extracted, a ValueError is raised.
    If the given parameter is a path, only the last chunk, "base name", is
    used."""
    if os.sep in string: # it's a path
        string = os.path.basename(string.rstrip(os.sep))
    match = config.VERSION_PATTERN.search(string)
    if not match:
        raise ValueError("%s doesn't contain a version number to extract" %
                string)

    # remove None groups and join the fragments together with a dot to make
    # StrictVersion happy
    match = ''.join([m for m in match.groups() if m is not None])
    if match.endswith('.'): # strip trailing dots
        match = match.rstrip('.').lstrip('.')
    return distutils.version.LooseVersion(match)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号