[英]How can i compare to binary images and verified are almost equal in python?
[英]How can I make a verified symbol in Python?
我正在开发一个使用 Python 下载和安装应用程序的项目。 存储应用程序信息的存储库在json
中有一行声明用户是否已验证,然后将其转换为True
或False
变量。 下载用户信息后,它使用rich
模块中的rich.print
函数在屏幕上打印信息。 我希望能够打印经过验证的符号,例如在 Twitter 上,我该怎么做?
manifest.json
{
"Name": "Test package",
"License": "Public Domain",
"Developer": "Hearth OS",
"DeveloperWWW": "https://hearth-os.github.io/",
"Description": "Hello World package.",
"Verified": "True",
"Version": "0.1",
"AppID": "com.hearth-os.test"
}
main.py (Lines 72-90)
# Write and open manifest.json
open("manifest.json", 'wb').write(r.content)
jsonFile = open("manifest.json", "r")
manifest = json.load(jsonFile)
# Read `manifest`
name = manifest['Name']
license = manifest['License']
developer = manifest['Developer']
www = manifest['DeveloperWWW']
description = manifest['Description']
verified = manifest['Verified']
version = manifest['Version']
id = manifest['AppID']
# Print `manifest`
rich.print('Package: ' + name)
rich.print('Developer: [link=' + www + ']' + developer + '[/link]')
rich.print('License: ' + license)
如果您的“验证符号”是一个 unicode 字符,您可以打印它:
if verified:
print("✅")
如果在 python2 中,您可能需要在文件顶部指定编码,否则会出现错误。 UTF-8 是一个常见的选择(也是 python3 中的默认值)
# -*- coding: utf-8 -*-
您还可以通过使用 unicode 转义序列来避免在代码中嵌入 unicode 文字字符(您需要查找所选符号的代码):
print("\u2705")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.