huangdongdong 发表于 2021-4-6 18:48:00

py繁体简体互转脚本

import easygui as g

g.msgbox('进入替换系统 ')
   



content = []#存入转换的字
complex_font = []#繁体字
familiar_style = []#简体字
#去除空格
pompt = '''砵 妸 屙 讹 俄 娥 峨 莪 锇 鹅 蛾 额 婀 厄 阨 呃 扼 苊 轭 垩 恶 饿 谔 鄂 阏 愕
萼 遏 腭 锷 鹗 颚 噩 諤 鳄 恩 蒽 摁 儿 而 鸸 鲕 尔 耳 迩 洱 饵 珥 铒 二 佴 贰 唔 诶'''
str_complex = pompt
for each in str_complex:
    if each == ' ':
      str_complex.replace(each,' ')
    else:
      complex_font.append(each)

prompt = '''砵 妸 屙 訛 俄 娥 峨 莪 锇 鵝 蛾 額 婀 厄 阨 呃 扼 苊 轭 垩 惡 餓 谔 鄂 阏 愕
萼 遏 腭 锷 鹗 颚 噩 諤 鳄 恩 蒽 摁 兒 而 鸸 鲕 爾 耳 迩 洱 餌 珥 铒 二 佴 貳 唔 诶'''
str_familiar = prompt
for each in str_familiar:
    if each == ' ':
      str_familiar.replace(each,' ')
    else:
      familiar_style.append(each)

#简体转繁体
dict1 = {}
dict1 = dict(zip(complex_font,familiar_style))
def fun(each_font):#不需要再次遍历
    if each_font in complex_font:
      content.append(dict1)

#繁体转简体
dict2 = {}
dict2 = dict(zip(familiar_style,complex_font))
def function(each_font):#不需要再次遍历
    if each_font in familiar_style:
      content.append(dict2)
      
#判断文件字体
def document_font(gfile_name):
    f_read = open(file_name)
    for each in f_read.read():
      if each in complex_font:
            fun(each)
      elif each in familiar_style:
            function(each)
      else:
            content.append(each)
      f_write = open(file_name,'w')
      f_write.writelines(content)
      f_write.close()
    f_read.close()

path = g.fileopenbox(default = '*.txt')

document_font(path)




这是我写简易版【只有E相关的字】的繁简互转脚本,涉及知识点有:1字典2列表3字符串4文件5分支与循环6easygui模块7函数,我学了但没用到的知识点有:1元组2递归3文件系统4with语句5异常机制6对象与类7永久储存。未用到的知识点不知如何运用在此脚本中。我本想运用easyguiz中的button函数,但不知道放在哪。希望各位大佬能够答疑解惑!!!

小伤口 发表于 2021-4-7 17:26:40

{:10_257:}easygui不是可以自动布局吗?

huangdongdong 发表于 2021-4-7 20:05:53

小伤口 发表于 2021-4-7 17:26
easygui不是可以自动布局吗?

???什么意思{:10_277:}

龙舞九天 发表于 2021-5-9 20:37:21

{:5_95:}

九州洋 发表于 2021-7-22 21:21:34

。。
页: [1]
查看完整版本: py繁体简体互转脚本