How would I make Python read a file line and use it as a variable?












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()









share|improve this question

























  • What have you tried searching for? If you want to read a line of a file, then this stackoverflow.com/questions/2081836/… ?

    – cricket_007
    Nov 28 '18 at 3: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?

    – cricket_007
    Nov 28 '18 at 3: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 3: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)

    – cricket_007
    Nov 28 '18 at 4:01











  • You should also read stackoverflow.com/a/15112149/2308683

    – cricket_007
    Nov 28 '18 at 4:03
















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()









share|improve this question

























  • What have you tried searching for? If you want to read a line of a file, then this stackoverflow.com/questions/2081836/… ?

    – cricket_007
    Nov 28 '18 at 3: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?

    – cricket_007
    Nov 28 '18 at 3: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 3: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)

    – cricket_007
    Nov 28 '18 at 4:01











  • You should also read stackoverflow.com/a/15112149/2308683

    – cricket_007
    Nov 28 '18 at 4:03














0












0








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()









share|improve this question
















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()






python file variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 4:08







EarthToAccess

















asked Nov 28 '18 at 3:32









EarthToAccessEarthToAccess

74




74













  • What have you tried searching for? If you want to read a line of a file, then this stackoverflow.com/questions/2081836/… ?

    – cricket_007
    Nov 28 '18 at 3: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?

    – cricket_007
    Nov 28 '18 at 3: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 3: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)

    – cricket_007
    Nov 28 '18 at 4:01











  • You should also read stackoverflow.com/a/15112149/2308683

    – cricket_007
    Nov 28 '18 at 4:03



















  • What have you tried searching for? If you want to read a line of a file, then this stackoverflow.com/questions/2081836/… ?

    – cricket_007
    Nov 28 '18 at 3: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?

    – cricket_007
    Nov 28 '18 at 3: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 3: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)

    – cricket_007
    Nov 28 '18 at 4:01











  • You should also read stackoverflow.com/a/15112149/2308683

    – cricket_007
    Nov 28 '18 at 4:03

















What have you tried searching for? If you want to read a line of a file, then this stackoverflow.com/questions/2081836/… ?

– cricket_007
Nov 28 '18 at 3:38







What have you tried searching for? If you want to read a line of a file, then this stackoverflow.com/questions/2081836/… ?

– cricket_007
Nov 28 '18 at 3: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?

– cricket_007
Nov 28 '18 at 3:40





If you just want to read a file that actually contains a single line, you have not found the read() method for file objects?

– cricket_007
Nov 28 '18 at 3: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 3:59





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 3: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)

– cricket_007
Nov 28 '18 at 4:01





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)

– cricket_007
Nov 28 '18 at 4:01













You should also read stackoverflow.com/a/15112149/2308683

– cricket_007
Nov 28 '18 at 4:03





You should also read stackoverflow.com/a/15112149/2308683

– cricket_007
Nov 28 '18 at 4:03












1 Answer
1






active

oldest

votes


















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.






share|improve this answer
























  • I definitely think that this will solve my question. Thanks!

    – EarthToAccess
    Nov 28 '18 at 4:12











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511705%2fhow-would-i-make-python-read-a-file-line-and-use-it-as-a-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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.






share|improve this answer
























  • I definitely think that this will solve my question. Thanks!

    – EarthToAccess
    Nov 28 '18 at 4:12
















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.






share|improve this answer
























  • I definitely think that this will solve my question. Thanks!

    – EarthToAccess
    Nov 28 '18 at 4:12














0












0








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.






share|improve this answer














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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 28 '18 at 4:06









cricket_007cricket_007

83k1145113




83k1145113













  • I definitely think that this will solve my question. Thanks!

    – EarthToAccess
    Nov 28 '18 at 4:12



















  • I definitely think that this will solve my question. Thanks!

    – EarthToAccess
    Nov 28 '18 at 4:12

















I definitely think that this will solve my question. Thanks!

– EarthToAccess
Nov 28 '18 at 4:12





I definitely think that this will solve my question. Thanks!

– EarthToAccess
Nov 28 '18 at 4:12




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511705%2fhow-would-i-make-python-read-a-file-line-and-use-it-as-a-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks