1
my_dict = {}
        with open('myFile.txt', 'r') as f:
            new_file = []
            for line in f:
                name_and_pass = line.split(":")
                name = name_and_pass[0]
                password = name_and_pass[1]
                """password = hash_passwd(password)"""
                my_dict.update({name : password})
                new_name_and_pass = name + ":" + password
                with open("output.txt", 'a+') as out:
                    out.write(new_name_and_pass + os.linesep)

the file says: Yossi:123 dui50000!!:aaa#### username3:secretPass8 AVI8#:abc

in the dictionary every password for no reason saves with \n at the end: {'Yossi': '123\n', 'dui50000!!': 'aaa####\n', 'username3': 'secretPass8\n', 'AVI8#': 'abc'}

MOS
  • 11
  • 1
  • 1
    The lines in the file will end with a newline character, because *that's what makes them lines in the file*. Use `.strip()` before the `.split()` to get rid of it. – jasonharper Aug 09 '22 at 16:54

0 Answers0