Skip to content

Instantly share code, notes, and snippets.

@conanca
Created January 6, 2014 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save conanca/8279361 to your computer and use it in GitHub Desktop.
Save conanca/8279361 to your computer and use it in GitHub Desktop.
将搜狗拼音导出的文本词库转换成ibus-libpinyin的用户词典
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''将搜狗拼音导出的文本词库转换成ibus-libpinyin的用户词典
by Conanca
'''
content = open("搜狗词库导出_2014_1_6.txt").read().decode('utf16').encode('utf8')
lines = content.split('\n')
f=open('ibus.txt','w')
for line in lines:
if line and ' ' in line and line[:1]!=';':
i=line.index(' ')
newline = line[i+1:-1] + ' '+line[1:i] + '\n'
f.write(newline)
print newline
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment