我有一个文字,其中包含行,ex
А
б
Вв
Гг
(非拉丁字母) 等
我想得到这个:
А
Б
ВВ
ГГ
在代码运行后我看到没有变化
这是代码:
f = open('sample.csv')
for line in f:
for sampleword in line.split():
print sampleword.upper()
非拉丁字符没有资格。有什么问题?
答案 0 :(得分:2)
在Python 2中大写非拉丁字母的解决方案是使用unicode字符串:
var mapProjection = new OpenLayers.Projection("EPSG:900913");
var dbProjection = new OpenLayers.Projection("EPSG:4326");
layer.preFeatureInsert = function (feature) {
if (!feature.projection)
feature.projection = dbProjection;
if (feature.projection != mapProjection)
feature.geometry.transform(feature.projection, mapProjection);
//do something...
}
map.addLayer(layer);
要从文件中读取unicode,您可以参考official Python manual:
从文件中读取Unicode非常简单:
words = [u'łuk', u'ćma']
assert [w.upper() for w in words] == [u'ŁUK', u'ĆMA']