火星文转换器-火星文转换器软件

火星文转换器-火星文转换器软件
浏览 (265)
  • 类型:
  • 更新:2024-07-17
  • 大小:310M
  • 所需权限:查看
  • 隐私政策:查看
借用py的re模块,寻找可能的火星文,再转换成本土文。 代码: ```python #!/usr/bin/python # -*- coding:utf-8 -*- # 代码功能将可能存在的火星文转换成本土文 # 利用py的re模块进行寻找和转换 # 区分中英文,保留符号 # 适合在命令行下使用 # author LoveTomorrow import re import sys import codecs # Output code type : utf-8, Heading,but IDE also need to set # So first open a txt which you want to change and save as utf-8 txt = codecs.open(sys.argv1,'r','utf-8') input = txt.read() txt.close() print input + '\n' # The quotation may happen after the combination of possible chinese and english # it may effinitively spilt out chinese first then recombination two list = re.findall(u'\u4e00-\u9fa5+',input) totalInput = re.findall(u'\u4e00-\u9fa5',input) def transferAll(n): return re.sub(n,i,turn) # each item from the result of findall for i in totalInput: if i in re.findall(u'a-z',input): try: # find English after word temp = totalInputtotalInput.index(i)+1 while temp in re.findall(u'a-z',input): # Concatenated before word temp += totalInputtotalInput.index(i)+2 if temp in re.findall(u'a-z',input): transfer = ''.join(transferAll(i) for i in temp) input = re.sub(u'((' + temp + u'))', transfer, input) if i + temp not in totalInput: input = re.sub(u'((' + i + u'))', transfer, input) except IndexError: break if input == "": print "Please put Chinese !",-1 sys.exit() print input ```
安卓版下载

同类推荐更多

专题合集更多>>

元气骑士内置菜单版最新版-元气骑士内置菜单版 暗号瞳-暗号瞳下载 海棠文学城小说网app下载 富士施乐Fuji-富士施乐fujixerox手机打印软件