Python提取中文关键词方法,,我想从一组中文字符串中取
Python提取中文关键词方法,,我想从一组中文字符串中取
我想从一组中文字符串中取得关键词,如“出版社”,然后将“朝华出版社”赋值给publisher。但是不知道应该怎么做,已经做了如下尝试。希望能够得到解答。
python>>>import sys>>>reload(sys)>>>sys.setdefaultencoding('utf8')>>>>>>import re>>>text = '''出版社: 朝华出版社出版年: 2007-12页数: 752定价: 49.80元装帧: 平装ISBN: 9787505417670'''>>>re.findall(r'出版社:(.*?)'.encode('utf-8'), text.encode('utf-8'))['']
pythontranslations = { '出版社': 'publisher', #...}text = '''出版社: 朝华出版社出版年: 2007-12页数: 752定价: 49.80元装帧: 平装ISBN: 9787505417670'''data = {}for l in text.strip().splitlines(): k, v = l.split(': ', 1) data[translations.get(k, k)] = vprint(data)
你问的是 Y 问题。以上是我猜测出来的 X 问题。参见:X-Y Problem | 酷 壳 - CoolShell.cn
print re.findall(r'出版社: ([\s\S]*?)\n', text)[0]
编橙之家文章,
相关内容
- python-rrdtool出现错误求解决MAC OS python pip install,python
- Python报错求助split method AttributeError不明白什么问题,
- Python GUI按键图标触发Python程序的操作问题,guipython,我
- Python支持用类实例作为List中元素吗,pythonlist,我把nba各
- Flask运行报错误不理解,flask不理解,代码只有一行topi
- Python 2.7版本中return输出格式疑问,python2.7,刚才那个代
- Python多线程提交插入数据库问题,python多线程,多线程读
- Python2.7 CGIHTTPServer OSError问题,,在windows上测试没
- Python re正则表达式替换字符,python正则表达式,python a
- 求简短实用python初学代码,python初学代码,如题,Pytho
评论关闭