>>> a=u'中国'
>>> a
u'u4e2du56fd'
>>> print a
中国
>>> print len(a)
2
>>> str=a.encode('gb2312') #以gb2312编码对unicode对像进行编码
>>> str
'xd6xd0xb9xfa'
>>> print str
中国
>>> print len(str)
4
>>>
>>> print str.decode('gb2312') 以gb2312编码对字符串str进行解码,以获取unicode
中国
>>> print len(str.decode('gb2312'))
2
>>>
#!/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/oracle@192.168.137.2/serv')
cursor = conn.cursor()
table_name="t300"
owner="system"
xsql='select process,sid from t300'
col=[]
r = cursor.execute(xsql)
for col in r:
#print col[0].decode('gbk')
if col[0].decode('gbk')==u'测试环境':
print col[0].decode('gbk')
print col[1]
print 1111
print len(col[0].decode('gbk'))
print len('测试环境')
print len(u'测试环境')
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/oracle/t1.py
测试环境
987789
1111
4
12
4