用Unicode向右到左覆盖的打印无法正常工作

发布于 2025-02-12 04:58:39 字数 542 浏览 1 评论 0原文

我正在尝试使用u202e Unicode RLO在Python中直接打印一些东西,但它不起作用。我在MACOS 12.4和11.6.7上使用Python 3.9.1、3.8.2和2.7.5尝试了ITERM2和终端。

[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'

当我尝试使用此格式向右打印时:
print(u“ \ u202eblah”)

打印:
blah

我希望输出是:

halb

我在做什么错? iterm也设置为utf-8

I'm trying to print something right to left in Python using the u202E unicode RLO and it's not working. I've tried this in iTerm2 and Terminal on MacOS 12.4 and 11.6.7 using Python 3.9.1, 3.8.2, and 2.7.5.

[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'

When I try to print right to left using this format:
print (u"\u202EBlah")

Which prints:
Blah

I expect the output to be:

halB

What am I doing wrong? iTerm is set for utf-8 as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬 2025-02-19 04:58:39

在Google Colab和Pycharm上运行以下代码会导致答案中给出的正确输出:

import sys
print(sys.getdefaultencoding())
print(u"\u202EBlah")

UTF-8
blah

确保您的python版本为3.x,它可能是版本错误,因为它在Windows 10和Linux上正常运行。

Running the following code on Google Colab and Pycharm results in the correct output given in the answer:

import sys
print(sys.getdefaultencoding())
print(u"\u202EBlah")

utf-8
‮Blah

Make sure your Python version is 3.x, it may be a version error, as it works well on Windows 10 and Linux.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文