Python Forum
Data is in and not in the file at the same time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data is in and not in the file at the same time
#1
Hello everyone!

At the moment I'm working on a simple Regiter/Login project which uses text file to store all the data.

username=input("Please enter your username: ")
    with open("Data.txt", "r") as DataFile:
        for i,line in enumerate(DataFile):
            if username in line:
                print("Found the user in line:",i)
                data=line.split()
                password=data[1]
                print(password)
        if username not in DataFile:
            print("Username ",username," not found!")
I get no error messages, but the problem is that both if statements are correct- at the same time username is and not in the file. Any help would be appreciated.


The output:

Please enter your username: Jeff
Found the user in line: 1
123
Username Jeff not found!


DataFile:

Jeff 123
Sandra 753
Mike 482
Reply


Messages In This Thread
Data is in and not in the file at the same time - by Arvydas_Kromelis - Jul-12-2019, 11:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Real time data satyanarayana 3 24,417 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  How to read rainfall time series and insert missing data points MadsM 4 2,192 Jan-06-2022, 10:39 AM
Last Post: amdi40
  Check last time file was accessed Pavel_47 4 2,844 Jun-01-2021, 05:47 PM
Last Post: Yoriz
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,324 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  find the header location in a .bin file without reading the whole file at a time SANJIB 0 2,235 Mar-05-2021, 04:08 PM
Last Post: SANJIB
  Naming the file as time and date. BettyTurnips 3 2,995 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips
  xml file creation from an XML file template and data from an excel file naji_python 1 2,124 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  how to change the range of read CSV file every time python file runs greenpine 6 4,499 Dec-08-2020, 10:11 PM
Last Post: greenpine
  ValueError: time data 'None' does not match format '%Y-%m-%dT%H:%M:%S.%f' rajesh3383 4 14,630 Sep-03-2020, 08:22 PM
Last Post: buran
  Formatting Data/Time with Pyodbc and openpyxl bearcats6001 0 2,295 Aug-17-2020, 03:44 PM
Last Post: bearcats6001

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020