Home python How to make a lines in two files on Python?

How to make a lines in two files on Python?

Author

Date

Category

There are 2 files. A random line is taken from the first. It is necessary to make it so that after choosing a string compared if it is in a 2 file if there is, choose again, and if not, then go further. Help please implement code.

import random
PROF = (Random.Choice (Open ('C: /Ussers/Denga/Desktop/Bunker/proff.txt', 'R', Encoding = "UTF-8"))))
F2 = Open ("C: /Ussers/denga/Desktop/Bunker/vibor.txt", 'W')
F2.WRITE (PROF)
"There must be a comparison"
My_File = Open ("rez.txt", 'W')
My_File.Write (PROF)
My_file.Close ()

Answer 1, Authority 100%

Approximately so

Def Do_something (Value):
  # Enough let it be
  My_file = Open ("rez.txt", 'A', Encoding = 'UTF-8')
  My_File.Write (Value.Rstrip ('\ n'))
  My_file.Close ()
if __name__ == '__main__':
  With Open ('values_to_compare.txt', 'R', Encoding = 'UTF-8') AS Values_TO_COMPARE:
    Values ​​= Values_to_Compare.Readlines ()
  With Open ('Values_List.txt', 'R', Encoding = 'UTF-8') AS VALUES_LIST:
    List_Values ​​= Values_List.Readlines ()
  For v in values:
    if v in list_values:
      do_something (V)

But the fact that above wrote is a comparison of strings (file contents) but not files. About comparison of files below:

import hashlib
if __name__ == '__main__':
  File_1 = Open ('stock_manager / manage.py', 'rb')
  File_2 = Open ('Test.py', 'Rb')
  hash_1 = hashlib.md5 (file_1.read ())
  hash_2 = hashlib.md5 (file_2.read ())
  File_1.Close ()
  File_2.Close ()
  Print (hash_1.hexdigest () == hash_2.hexdigest ())

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions