用Python实现两个磁盘文件A和B,各存放一行字母,要求把这两个文件中信息合并(按字母顺序排列),输出到一个新文件C中。

def get_other_file(strpath, otherpath):
    """
    有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中信息合并(按字母顺序排列),输出到一个新文件C中。
    :return:
    """
    objfile_one = open(strpath, "r")
    objfile_other = open(otherpath, "r")

    strline_one = objfile_one.read()
    strline_other = objfile_other.read()

    objfile_one.close()
    objfile_other.close()

    strline = strline_one + strline_other
    # return list type
    strline = sorted(strline)
    strline = "".join(strline)


    objfile = open("c.txt", "w")
    objfile.write(strline)
    objfile.close()

  

原文地址:https://www.cnblogs.com/hxiaoli/p/8393082.html