'python stream file : no idea why this doesnt work ( but i have same stream id every time )

PS : (due to my country's teaching program, I need to write python code like this )
Hello, I have no idea why this doesn't work:

from pickle import load,dump
# verif function to check existence of a caractére in a file 
def verif(alphabet):
    f50 = open(r"C:\Users\TUNEZ-1\Desktop\3 informatique math universe\f2.dat","rb")
    print("first id",id(f50))
    End_Of_File = False
    test_existence = True
    while(End_Of_File == False):
        try :
            char = load(f50)
            if char == alphabet:
                 test_existence = False
       except:
            End_Of_File = True
        
    f50.close()
    return test_existence
#creation of the file
f2 = open(r"C:\Users\TUNEZ-1\Desktop\3 informatique math universe\f2.dat","wb")
N = 10
for i in range(10):
    #getting 10 input's from the user and they must be unique
    test = True
    while(test == True):
        alphabet = input(f"saisir alphabet N:{i}")
        if verif(alphabet) == True:
             test = False
        else:
             print("Erreur l'alphabet existe")
    dump(alphabet,f2)

f2.close()

so basically what I'm doing is trying to write 10 alphabet characters in my f2.dat file and the alphabet's must be unique so I created a verif() function to always load all previous characters from the file and check if the input exists if it does the program must print error to the user and ask him to give another input

what i mannaged to notice that my f50 stream have always the same id every time to function verif() is called as you can see here
i can enter the same charactere everytime

since the object has the same id everytime i guess the file stream didnt get close cause normaly the function verif() is bein called 10 times and F50 every time should be a new variable with new stream so it can read changes



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source