python:扩展的ASCII码 [英] python: extended ASCII codes

查看:283
本文介绍了python:扩展的ASCII码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何附加并在python中打印扩展的ASCII代码. 我有以下内容.

Hi I want to know how I can append and then print extended ASCII codes in python. I have the following.

code = chr(247)

li = []
li.append(code)
print li

当python打印出来的结果应为除号时,其结果为['\ xf7'].如果我直接将打印代码简单地称为打印代码",那么我会得到分隔符号,但是如果将其附加到列表中则不会.我在做什么错了?

The result python print out is ['\xf7'] when it should be a division symbol. If I simple print code directly "print code" then I get the division symbol but not if I append it to a list. What am I doing wrong?

谢谢.

推荐答案

打印列表时,它将输出所有元素的默认表示形式-即通过在每个元素上调用repr().根据设计,字符串的repr()是其转义的代码.如果要正确输出列表的所有元素,则应将其转换为字符串,例如通过', '.join(li).

When you print a list, it outputs the default representation of all its elements - ie by calling repr() on each of them. The repr() of a string is its escaped code, by design. If you want to output all the elements of the list properly you should convert it to a string, eg via ', '.join(li).

请注意,正如评论中所指出的那样,实际上并没有扩展ASCII"之类的东西,只有各种不同的编码.

Note that as those in the comments have stated, there isn't really any such thing as "extended ASCII", there are just various different encodings.

这篇关于python:扩展的ASCII码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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