从右到左和从左到右打印得很好 [英] Right-to-Left and Left-to-Right printed nicely

查看:66
本文介绍了从右到左和从左到右打印得很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望它在单词旁边生成数字,以便我可以要求用户使用相应的数字选择单词.

I want it to produce the number next to a word so that I can ask the user to select the word by using the corresponding number.

这是我的代码

alt_words = hlst
loopnum = 8
for i in range(loopnum):
        if i < len(alt_words):
            print('{0}. {1:<20}'.format((i+1), alt_words[i]), end =' ')
            if i == 0:
                print('', end=' ')
        if i + 9 <= len(alt_words):
            print('{0}. {1:<20}'.format((i+9), alt_words[i+8]), end =' ')
        if i + 17 <= len(alt_words):
            print('{0}.  {1:<20}'.format((i+17), alt_words[i+16]), end=' ')
        print('\n'+'-'*80)

它产生这个

每行的第一个数字打印在左边,但单词在右边,而其余的数字和单词则打印 RTL.似乎一旦 python 开始在一行 LTR 上打印,它就可以切换到 RTL,但不能从 RTL 返回到 LTR.请注意,如何在每行第二组数字的数字右侧打印句点.

The first number of each line gets printed on the left, but the word on the right, while the rest of the numbers and words get printed RTL. It seems that once python has started printing on a line LTR it can switch to RTL, but not back from RTL to LTR. Note how even the periods are printed to the right of the number for the second set of numbers on each line.

它工作得很好,用英文单词看起来也不错:

It works perfectly well and looks nice with english words:

我猜想解决的办法可能是将数字放在单词后面,但我认为一定有更好的方法.

I am guessing a work around might involve putting the number after the word, but I figure there must be a better way.

推荐答案

在开头放一个 Right-to-Left Embedding 字符,u'\u202B'每个希伯来语单词,以及一个 Pop Directional Formatting 字符,u'\u202C',在每个单词的末尾.

Put a Right-to-Left Embedding character, u'\u202B', at the beginning of each Hebrew word, and a Pop Directional Formatting character, u'\u202C', at the end of each word.

这会将希伯来语单词设置为 LTR 文档中的 RTL 部分.

This will set the Hebrew words apart as RTL sections in an otherwise LTR document.

(请注意,虽然这会产生正确的输出,但您还依赖于运行此脚本的终端应用程序已经实现了 Unicode 双向算法 正确.)

(Note that while this will produce the correct output, you're also dependent on the terminal application in which you're running this script having implemented the Unicode Bidirectional Algorithm correctly.)

这篇关于从右到左和从左到右打印得很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆