为什么Python的string.printable包含不可打印的字符?

Odd*_*ing 12 python character-encoding

我在一个问题中有两个String.printable的谜团.

首先,在Python 2.6中:

>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
Run Code Online (Sandbox Code Playgroud)

看看字符串的结尾,你会发现'\ x0b\x0c'像拇指一样伸出来.他们为什么在那里?我使用的机器设置为澳大利亚设置,因此不应该有任何重音字符等.

接下来,尝试运行此代码:

for x in string.printable: print x,
print
for x in string.printable: print x
Run Code Online (Sandbox Code Playgroud)

第一行成功打印由空格分隔的所有字符.两个奇怪的字符结果为男性和女性符号.

第二行成功打印除了换行符之外的所有字符.男性符号打印; 女性符号被替换为缺少的字符(方框).

我确信Python并不是出于性别偏见,所以有什么区别呢?

Spa*_*arr 26

"可以在屏幕上显示"的"可打印"有所不同.您的终端显示低ascii打印机控制代码0x0B和0x0C作为男性和女性符号,因为这是您的字体中的那些索引包含的.这些字符更准确地描述为Vertical Tabulator和Form Feed字符.这两个字符以及\ t\r和\n都是可打印的,并且在打印机上做了很好的定义.


jfs*_*jfs 6

从cmd.exe内:

>>> print '\x0b'
?
>>> print '\x0c'
?
>>> print '\f' # form feed
?
>>> print '\v' # vertical tab
?
>>>
Run Code Online (Sandbox Code Playgroud)

内部Emacs:

>>> print '\f\v'
^L^K
Run Code Online (Sandbox Code Playgroud)

以下是格式(5) '手册页的摘录:

| Sequence | Character    | Terminal Action                             |
|----------+--------------+---------------------------------------------|
| \f       | form-feed    | Moves the printing position to the initial  |
|          |              | printing position of the next logical page. |
| \v       | vertical-tab | Moves the printing position to the start of |
|          |              | the next vertical tab position. If there    |
|          |              | are no more vertical tab positions left on  |
|          |              | the page, the behavior is undefined.        |