将 unicode 字段转换为文本

Converting unicode fields into texts

我有一个 shapefile (.shp),其中包含用日语编写的字段名称。我想使用以下程序读取日语中的字段名称:

import ogr
infile = r"E:\shp\test.shp"
ds = ogr.Open(infile,0); slayer = ds.GetLayer(0)
fieldNames = [slayer.GetLayerDefn().GetFieldDefn(i).GetName() for i in range(0,slayer.GetLayerDefn().GetFieldCount())]

for x in fieldNames:
    print x

但是,打印出来如下,不可读

ツwヘW
ツxヘW
’c’n–¼

如何获取字段名称的可读日语文本?

我也试过 x.decode('utf8'),但收到错误消息 UnicodeDecodeError: 'utf8' codec can't decode byte 0x95 in position 0: invalid start byte

伙计们,怎么做?

这里不是肯定的,只是想提供帮助,但也许尝试像这样将字符串转换为 unicode 序列?

a = "Hello, World!"
u = unicode(a,'utf-8')

print type(a)
print a
print type(u)
print u

输出:

<type 'str'>
Hello!
<type 'unicode'>
Hello!