账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    请问怎么把这两段相似代码用函数封装一下,使它简洁一些?
    34
    0
    with open("email_encrypt.txt", "w", encoding="utf-8") as fw:
        fw.write(get_email("wenben.txt"))
    
    file_data = ""
    with open("email_encrypt.txt", "r", encoding="utf-8")as fr:
        for line in fr.readlines():
            t = md5_encode(line)
            if "\n" in line:
                line = line.replace("\n", " " + t + "\n")
            else:
                line = line + " " + t
            file_data += line
    
    with open("email_encrypt.txt", "w", encoding="utf-8")as fn:
        fn.write(file_data)
    
    
    with open("phone_encrypt.txt", "w", encoding="utf-8") as fw2:
        fw2.write(get_phonenumber("wenben.txt"))
    
    file_data2 = ""
    with open("phone_encrypt.txt", "r", encoding="utf-8")as fr2:
        for line in fr2.readlines():
            t2 = md5_encode(line)
            if "\n" in line:
                line = line.replace("\n", " " + t2 + "\n")
            else:
                line = line + " " + t2
            file_data2 += line
    
    with open("phone_encrypt.txt", "w", encoding="utf-8")as fm:
        fm.write(file_data2)
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • ぃ她是我得心脏 普通会员 1楼

      很抱歉,你没有提供需要封装的代码。如果你能提供一段代码,我将很乐意帮助你进行封装。

    更多回答
    扫一扫访问手机版