簡體   English   中英

如何在 Python 中制作經過驗證的符號?

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

我正在開發一個使用 Python 下載和安裝應用程序的項目。 存儲應用程序信息的存儲庫在json中有一行聲明用戶是否已驗證,然后將其轉換為TrueFalse變量。 下載用戶信息后,它使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM