0

Tried looking it up elsewhere, to no avail. How would I do something like, having Python read a file line, then use what's in that line as a variable for a different file?

Essentially, I want a different file that acts as a verification key, and when the content of the file (the passkey) is entered, my code recognizes that and passes it, then opening said file. I also want to be able to read a lockout file to check and see whether the user should be "locked out", and need to enter the passkey. Any possible way of doing this?

Update: I edited the code a little by my self, just so everyone is aware.

filename = ".UbuntuAlt/.Info.txt"
#I'm aware that the use of many of the "quit()" functions is ambiguous but idc
verify = ".UbuntuAlt/.Verify.txt"
locktxt = ".UbuntuAlt/.Lockout.txt"
#this is where I want to make ".Lockout.txt" verify whether the passkey needs to be used, and set variable "lockout" accordingly
infotxt = open(filename, "r")
verifyread = open(verify, "r")
locktestw = open(locktxt, "w")
locktestr = open(locktxt, "r")

if lockout == True:
    verify1 = raw_input("Please enter verification key: ")
    #this is where I want the code to read ".Verify.txt" and use its content as the passkey
    if verify1 == "look above":
        for line in infotxt:
            print line,
            infotxt.close()
            verifyread.close()
        lockout = False
        #this is where I want ".Lockout.txt" edited to be false-- I can do that myself though
        lockoutq = raw_input("Lockout is disabled. Reenable? [Y/n]: ")
        if lockoutq == "y" or "Y" or " ":
            #also where I plan on editing it
            quit()
        if lockoutq == "n" or "N":
            quit()
        else:
            lockdownerr = raw_input("Invalid input. [2] attempts remaining. Reenable? [Y/n]: ")
            if lockdownerr == "y" or "Y" or " ":
                #aaa
                quit()
            if lockdownerr == "n" or "N":
                quit()
            else:
                lockdownfinal = raw_input("Invalid input. [1] attempt remaining. Reenable? [Y/n]: ")
                if lockdownerr == "y" or "Y" or " ":
                    #aaa
                    quit()
                if lockdownerr == "n" or "N":
                    quit()
                else:
                    print "Invalid input. Enabling anyway."
                    #you get the point
                    quit()
    else:
        verifyread.close()
        print "You've inputted an invalid key. Aborting."
        quit()
else:
    for line in infotxt:
        print line,
        infotxt.close()
        verifyread.close()
    lockoutq2 = raw_input("Lockout is disabled. Reenable? [Y/n]: ")
    if lockoutq2 == "y" or "Y" or " ":
        #same as above w/ editing the lockout text
        quit()
    if lockoutq2 == "n" or "N":
        quit()
    else:
    lockdownerr = raw_input("Invalid input. [2] attempts remaining. Reenable? [Y/n]: ")
        if lockdownerr == "y" or "Y" or " ":
            #aaa
            quit()
        if lockdownerr == "n" or "N":
            quit()
        else:
            lockdownfinal = raw_input("Invalid input. [1] attempt remaining. Reenable? [Y/n]: ")
            if lockdownerr == "y" or "Y" or " ":
                #aaa
                quit()
            if lockdownerr == "n" or "N":
                quit()
            else:
                print "Invalid input. Enabling anyway."
                #you get the point
                quit()
EarthToAccess
  • 71
  • 1
  • 10
  • What have you tried searching for? If you want to read a line of a file, then this https://stackoverflow.com/questions/2081836/reading-specific-lines-only-python ? – OneCricketeer Nov 28 '18 at 03:38
  • If you just want to read a file that actually contains a single line, you have not found the `read()` method for file objects? – OneCricketeer Nov 28 '18 at 03:40
  • I need a way to assign that line to a variable, so that I could make a `raw_input` line that requires whatever that line is in order to continue certain pieces of code. – EarthToAccess Nov 28 '18 at 03:59
  • I don't understand the question, but assuming you can get a line using the above methods, `data = raw_input("input something for line: " + line)` – OneCricketeer Nov 28 '18 at 04:01
  • You should also read https://stackoverflow.com/a/15112149/2308683 – OneCricketeer Nov 28 '18 at 04:03

1 Answers1

0

this is where I want the code to read ".Verify.txt" and use its content as the passkey

I suggest you start with a much smaller example e.g.

verify1 = raw_input("Please enter verification key: ")
passkey = open(".Verify.txt").read().strip()
if verify1 == passkey:
    print("Match")
else:
    print("Not Match")

Similarly, you can open .Lockout.txt and check its contents for lockout

If you need to open a file for read/write, use "rw", not two variables for doing either against the same file.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245