- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 python 中的模式打印字母“A”
def printA(length,height,symbol):
a = [[" " for i in range(length)] for i in range(height)]
for i in range(height):
for j in range(length):
if j == 0 or i == 0 or i == height // 2 or j == length - 1:a[i][j] = symbol
return a
它适用于普通字符,如
*,/+,-,#,$,% .. etc.,
输出:
#######
# #
# #
#######
# #
# #
# #
表情符号
😀😀😀😀😀😀😀
😀 😀
😀 😀
😀😀😀😀😀😀😀
😀 😀
😀 😀
😀 😀
如果我能找到表情符号的长度,那么我将能够将空格更改为表情符号的长度,这样就不会出现这个问题,有什么办法可以做到这一点
Note : The above code works only for characters and not strings
A
但是当我尝试打印
A
的序列时即不止一次它只是放错了表情符号
AAAAA
输出 :
AAAAA
像这样
a = printA(7,7,"😀")
for i in a:
for k in range(5):print(*(i),end=" ")
print()
最佳答案
重要的是显示字符的字体中字形的宽度,而不是作为 Python 字符串的字符长度。此信息不适用于 Python,但我们可以根据 symbol
是否可用来猜测。是 wide East Asian character ,由 unicodedata 报告的 unicode 标准定义模块。
import unicodedata
def printA(length, height, symbol):
# Two spaces for "wide" characters, one space for others.
spacer = ' ' if unicodedata.east_asian_width(symbol) == 'W' else ' '
a = [[spacer for i in range(length)] for i in range(height)]
for i in range(height):
for j in range(length):
if j == 0 or i == 0 or i == height // 2 or j == length - 1:
a[i][j] = symbol
return a
使用东亚宽度属性有效,因为
emoji characters were first developed through the use of extensions of legacy East Asian encodings, such as Shift-JIS, and in such a context they were treated as wide characters. While these extensions have been added to Unicode or mapped to standardized variation sequences, their treatment as wide characters has been retained, and extended for consistency with emoji characters that lack a legacy encoding.
关于python - 使用python3查找表情符号的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63410948/
我遇到了 Handlebars 表达式 {{!< default}}我不明白。在问这个问题之前,我曾尝试在谷歌上搜索答案。但是,我找不到任何答案。谁能解释一下这个表达式是什么意思? 最佳答案 在 Ha
经常有朋友问起,如何在im即时通讯中实现发送图片、视频、语音和表情? 为此,小编特意写了一个vue版本的demo,实现了图片视频文件和表情的的发送,参考这个demo源代码,相信你就可以轻松的用un
这里是一个网站 ( https://twitchemotes.com/apidocs ),它展示了一个用于获取 twitch 表情的 API(基本上是描述属于不同用户的一组图像的 json)。 API
使用 Python 3,像下面这样的简单脚本应该按预期运行,但似乎会因 unicode 表情字符串而窒息: import re phrase = "(╯°□°)╯ ︵ ┻━┻" pattern = r
我试图弄清楚表情符号(表情)选择是如何在 Facebook 应用和 Google Hangouts 应用上实现的。我查看了 Android API 示例中的 SoftKeyboard 演示应用程序,但
我正在尝试在 android 通知文本中显示笑脸(或图像范围)。它不起作用。有人知道怎么做吗?谢谢。 代码如下: SpannableStringBuilder builder = new Spanna
我是一名优秀的程序员,十分优秀!