Ответы пользователя по тегу Python
  • Как достать новые строки из текстового файла?

    @ArtemZA
    Студент
    на Python
    first = 'master.txt'
    second = 'file.txt'
    directory = 'C:\\new\\'
    
    A = []
    B = []
    C = []
    D = []
    
    
    def FileRead(file):
        f = open(directory + file , 'r' , encoding = "utf-8")
        for i in f:
            if q == 0:
                A.append(i)
            if q == 1:
                B.append(i)
        f.close()
       
    def FileWrite(file,spisok):
        f = open(directory + file , 'w')
        for line in spisok:
            f.write(line + '\n')
        f.close()
            
      
    for q in range(0,2):
        if q == 0:
            FileRead(first)
        if q == 1:
            FileRead(second)
    
    A = [line.rstrip() for line in A]
    B = [line.rstrip() for line in B]
    for i in A:
        if not i in B:
            print(i)
            C.append(i)
    
    for i in B:
        if i in A:
            print(i)
            C.append(i)
    
    for i in B:
        if not i in A:
            print(i)
            C.append(i)
            D.append(i)
    
    FileWrite('newmaster.txt', D)
    FileWrite('new.txt',C)
    Ответ написан
    Комментировать