简体   繁体   English

如何在 Python 中制作经过验证的符号?

[英]How can I make a verified symbol in Python?

I am working on a project that uses Python to download and install applications.我正在开发一个使用 Python 下载和安装应用程序的项目。 The repos where the application info is stored has a line in json that states if the user is verified, this is then converted to a True or False variable.存储应用程序信息的存储库在json中有一行声明用户是否已验证,然后将其转换为TrueFalse变量。 After downloading the info on the user it prints the info on screen using the rich.print function, in the rich module.下载用户信息后,它使用rich模块中的rich.print函数在屏幕上打印信息。 I want to be able to print a verified symbol, like on Twitter, how can I do this?我希望能够打印经过验证的符号,例如在 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)

If your "verified symbol" is a unicode character you can just print it:如果您的“验证符号”是一个 unicode 字符,您可以打印它:

if verified:
    print("✅")

If in python2 you might need to specify an encoding at the top of your file or you will get an error.如果在 python2 中,您可能需要在文件顶部指定编码,否则会出现错误。 UTF-8 is a common choice (and the default in python3) UTF-8 是一个常见的选择(也是 python3 中的默认值)

# -*- coding: utf-8 -*-

You can also avoid embedding unicode literal characters in your code by using the unicode escape sequence (you need to look up the code for your symbol of choice):您还可以通过使用 unicode 转义序列来避免在代码中嵌入 unicode 文字字符(您需要查找所选符号的代码):

print("\u2705")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM