python 中文显示 \xb2\xe2\xca\xd4\xd6\xf7\xbb\xfa

# !/usr/bin/env python
# -*- coding: utf-8 -*-
import cx_Oracle
from pprint import pprint
import csv
import time
import re
import binascii

conn = cx_Oracle.connect('system/[email protected]/serv')
cursor = conn.cursor()
xsql='select * from tlcb_mon_device'
r = cursor.execute(xsql)
print r
for x in r:
    print x
    print  type(x)


返回:

C:\Users\TLCB\Desktop\ansible>python a1.py
>
('192.168.137.3', '\xb2\xe2\xca\xd4\xd6\xf7\xbb\xfa')




中文怎么显示这个吊样?

# !/usr/bin/env python
# -*- coding: utf-8 -*-
import cx_Oracle
from pprint import pprint
import csv
import time
import re
import binascii

conn = cx_Oracle.connect('system/[email protected]/serv')
cursor = conn.cursor()
xsql='select * from tlcb_mon_device'
r = cursor.execute(xsql)
print r
for x in r:
    print x
    print x[0]
    print len(x[0])
    print x[1]
    print x[1].decode('gbk').encode('utf-8')
    print len(x[1])
    y=x[1].decode('gbk').encode('utf-8')
    print len(y)
    print  type(x)

C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a21.py
>
('192.168.137.3', '\xb2\xe2\xca\xd4\xd6\xf7\xbb\xfa')
192.168.137.3
13
��������
测试主机
8
12


Process finished with exit code 0

你可能感兴趣的:(python,unicode,utf8,json转换)