从GitHub存储库获取版本号

时间:2019-01-02 20:49:14

标签: python python-3.x

我无法从GitHub帐户上存储库中的文本文件中获取应用程序的当前版本号。

def version_check(self):
    # Fetch version number from GitHub repo

    get_version = urlopen('https://raw.githubusercontent.com/myaccount/myproject/master/VERSION')
    #get_version.read().decode("utf-8") (No terminal output)
    print(get_version.read())
    print(get_version.headers['content-type'])

    #if get_version.read() == version_number:
    #    return True
    #else:
    #    return False

我得到这个终端输出:

    b'1.6\n'
    text/plain; charset=utf-8

如何格式化输出?我相信它们是字节字面量,但我为找到解决方案而感到困惑。

1 个答案:

答案 0 :(得分:1)

这是“字节”类型的值。您需要调用它的解码函数以将其转换为字符串。

myBytesVal = myBytesVal.decode('utf-8')