Home > Enterprise >  How to check a text editor (file) for the presence of a certain word that the user entered
How to check a text editor (file) for the presence of a certain word that the user entered

Time:06-08

There is a variable email = String Var() that transmits the entered login, I want to check through the open file whether the entered login is already in the text editor Users.txt ,but the compiler writes that it cannot read with the StringVar() data type, the question is that how can I convert the email variable so that open file can read it.. And of course, if there is a string that the user entered in the Entry as login, then a warning is issued that occupied.

email = tk.StringVar()

email_entry = ttk.Entry(sign in, textvariable=email)

file = open('C://Users.txt', 'r') data file = file.readlines() for line in datafile: if email.get() in line: return True

Compiler error:

datafile = file.readlines() io.UnsupportedOperation: not readable

I know that swears at the Var type in the line, with a normal tc line, this has never happened, but I don't know how you can get a different input string from the user in the Entry through a regular string, for example.

CodePudding user response:

The last line should be broken up into separate commands, and should be written to ensure the file is closed.

with open('C://Users.txt', 'r') as file:
    datafile = file.readlines() 
    for line in datafile:
        if email.get() in line:
            return True
return False
  • Related