python在ex中搜索俄语子串

2024-10-01 09:15:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我想阅读excel文件并提取一些有关某些人的信息。你知道吗

这就是我要做的

import xlrd
dir = './schfiles';
files = os.listdir(dir);
f = files[0];
book = xlrd.open_workbook(dir+"/"+files[0]);
sh = book.sheet_by_index(0)
t = sh.cell_value(rowx=xlr2i(35),colx=xlc2i('F'))
t.find(u"Усманов")

var t中写入的字符串是u'\u0434\u043e\u0446。\u0423\u0441\u043c\u0430\u043d\u043e\u0432\u0411.\u0428.'看起来像“Доц”。УСМааааоВБ.Ш。”

u“УСМааааааоВ”表示为u'\xd3\xf1\xec\xe0\xee\xe2'

我尝试将这两个字符串编码为“utf8”,使用外部libs对它们进行解码,但没有任何帮助。你知道吗

有人知道怎么可能在这里找到一个子串吗?你知道吗


Tags: 文件字符串import信息osshdirfiles
1条回答
网友
1楼 · 发布于 2024-10-01 09:15:37

使用# -*- coding: utf-8 -*-作为脚本的第一行,告诉intepreter您使用的是哪种编码。你知道吗

# -*- coding: utf-8 -*-

import os
import xlrd

dir = './schfiles'
files = os.listdir(dir)
f = files[0]

workbook_path = os.path.join(dir, files[0])
book = xlrd.open_workbook(workbook_path)

sh = book.sheet_by_index(0)
t = sh.cell_value(rowx=xlr2i(35),colx=xlc2i('F'))
t.find(u"Усманов")

相关问题 更多 >