print "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf".decode('base64')#no
感谢这个字符串'base64'或'utf-8'的编码是什么?我怎样才能得到它可读
和
如果我有 '4-12个英文字母,数字和下划线'
我怎样才能得到字符串'4-12 \ u4e2a \ u82f1 \ u6587 \ u5b57 \ u6bcd \ u3001 \ u6570 \ u5b57 \ u548c \ u4e0b \ u5212 \ u7ebf'
是
print '4-12个英文字母、数字和下划线'.decode('what')#
我写:
print u'4-12个英文字母、数字和下划线'.encode('unicode-escape')
其打印
4-12\xb8\xf6\xd3\xa2\xce\xc4\xd7\xd6\xc4\xb8\xa1\xa2\xca\xfd\xd7\xd6\xba\xcd\xcf\xc2\xbb\xae\xcf\xdf
不是字符串“4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf
print u'4-12个英文字母、数字和下划线'.decode('utf-8').encode('unicode-escape')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "encodings\utf_8.pyo", line 16, in decode
UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-27: ordinal not in range(128)
没有 'U' 也是错误:
print '4-12个英文字母、数字和下划线'.decode('utf-8').encode('unicode-escape')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "encodings\utf_8.pyo", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 4: unexpected code byte
它的确定,由于
>>> print '4-12个英文字母、数字和下划线'.decode('gb2312').encode('unicode-escape')
4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf
我不知道它是什么,但它不是base64。 – Joe 2010-01-18 03:27:34
\ u = unicode代码点也许? – 2010-01-18 03:28:15
尝试一种新的发布方式,这样它不会被关闭吗? http://stackoverflow.com/questions/2083389/how-do-i-break-this-script-closed – epascarello 2010-01-18 04:22:08