Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在shell中打印图标_Python_Icons - Fatal编程技术网

Python 在shell中打印图标

Python 在shell中打印图标,python,icons,Python,Icons,下面是一些示例,当在IDLE3中包含的Python 3.4.3 Shell中运行时,它将输出特殊字符(图标)。当我在终端中运行相同的代码时,字符将根本不会出现 """ Some print functions with backslashes. In IDLE3 they will output 'special characters' or icons. In a terminal, they will not output anything. """ #Somtimes a

下面是一些示例,当在IDLE3中包含的Python 3.4.3 Shell中运行时,它将输出特殊字符(图标)。当我在终端中运行相同的代码时,字符将根本不会出现

""" Some print functions with backslashes.
    In IDLE3 they will output 'special characters' or icons.
    In a terminal, they will not output anything. """

#Somtimes a visual effect.
print ("a, \a") #telephone
print ("\a")
print ("b, \b") #checkmark
print ("c, \c") # just a '\c' output.
# other letters like '\c' kept out the rest of this list.
print ("f, \f") #quarter note (musical)
print ("n, \n") #newline
print ("r, \r") #halve note (musical)
print ("t, \tTabbed in")
#print ("u, \u") #syntaxerror
print ("\u0000") #empty
print ("\u0001") #left arrow
print ("\u0002") #left arrow underline
print ("\u0003") #right arrow (play)
print ("v, \v") #eighth note (musical)
print ("\x01") # == '\u0001' __________(x == 00 ?)
print ("\1") # == '\u0001' == '\x01'

#some more fooling around
print ("\1") #left arrow
print ("\2") #underlined left arrow
print ("\3") #right arrow
print ("\4") #underlined right arrow
print ("\5") #trinity
print ("\6") #Q-parking
print ("\7") #telephone
print ("\8")
print ("\9")
print ("\10") #checkmark
print ("\11 hi") #tab
print ("\12 hi") #newline
print ("\13") #8th note
print ("\14") #4th note
print ("\15") #halve note
print ("\16") #whole note
print ("\17") #double 8th note
print ("\18")
print ("\19")
print ("\20") #left arrow (black)
print ("\21") #right arrow (black)
print ("\22") #harry potter
print ("\23") #X-chrom-carrying cell
print ("\24") #Y-chrom-carrying cell
print ("\25") #diameter for lefties
print ("\26") #pentoid
print ("\27") #gamma?
print ("\28") #I finally realised this will have to do with triple
              # binary per character? 111 = 7, stop = 8

print ("\30") #
print ("\31") # female
print ("\32") # male
print ("\33") #
print ("\34") # clock
print ("\35") # alfa / ichtus
print ("\36") # arc
print ("\37") # diameter

print ("\40hi") # spaces? I don't know. 


# This does not work by the way:

##import string

###No visual effect.
##alfa = string.ascii_lowercase
##for x in alfa:
##    print ("\%s" % x)
我的一些Python Shell 3.4.3。IDLE3中的输出:

这些“特殊”字符c.q.图标是否以任何方式使用?是否有一些我可以阅读的文件阻止我提出这个问题


我在Stack上查看了有关此问题的其他问题,但我发现所有人都试图传入“外来”(如来自单词符号或其他)字符,并使它们通过Python打印。

如果您处于空闲状态,请单击“选项”和“配置空闲…”可以看到您使用的字体。字体将字符数字转换为您看到的内容。不同的字体可以产生不同的字符

例如:

>>> print(u'\u2620')
☠
我通过搜索找到了,而且可以找到

并非所有字体都支持所有字符

Unicode字符以特定主题的形式组织。我喜欢头骨来自的街区

编码 另外一个重要的问题是使用哪种编码。编码确定如何将字符映射到。字符必须从
print(u'\0001')
sys.stdout
到读取它的控制台和窗口管理器。每个步骤只理解字节-256个可能的字符

因此,有各种编码,例如拉丁-1,它使用256个可能的字符,并将它们映射到unicode块上。我认为拉丁语1使用前两个街区。有一些编码,例如UTF-8使用8位=1字节及以上,或UTF-16使用2字节及以上,或UTF-32使用4字节及以上,允许通过不同步骤从打印中传输更多字符

如果我想用拉丁语1对头骨和交叉骨进行编码,我会得到以下错误:

>>> u'\u2620'.encode('latin-1')

Traceback (most recent call last):
  File "<pyshell#32>", line 1, in <module>
    u'\u2620'.encode('latin-1')
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2620' in position 0: ordinal not in range(256)

使用不同的编码进行编码和解码会改变字符。如果您想使用有趣的字符,请使用unicode和UTF-8。

鉴于这个问题是关于空闲和您的终端之间的不同行为,Ubuntu 14中的哪个终端?终端模拟器。Kernel:3.19.0-28-generic这有帮助吗?不是所有的字符都是可打印的,我想idle没有正确打印输出。您的终端使用什么字体?字体:“DejaVu Sans Mono Book”字体大小:“10”编码:“utf-8”
>>> print u'\u0436', repr(u'\u0436'.encode('cp1251')) # cyrillic works
ж '\xe6'
>>> print u'\u0436', repr(u'\u0436'.encode('cp1252')) # latin-1 fails
ж

Traceback (most recent call last):
  File "<pyshell#41>", line 1, in <module>
    print u'\u0436', repr(u'\u0436'.encode('cp1252')) # latin-1
  File "C:\Python27\lib\encodings\cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u0436' in position 0: character maps to <undefined>
>>> print u'\u0436\u2620', repr(u'\u0436\u2620'.encode('utf-8'))
ж☠ '\xd0\xb6\xe2\x98\xa0'