I wrote a script in Python and I ran it in the command line. The first part of the output is what I had expected it to be. However, it does not print the first line as I want it to with readline()
. I am asked the second question but when I answer "yes" it prints an empty line. When I remove the if statement and the first question it works fine, but I can't get it to work with the if statement.
Here's the script:
script, filename = argv
print("I'm going to open the file.")
txt1 = open(filename)
question1 = raw_input("Do you wanna see the content? ")
if (question1 == "yes" or question1 == "Yes"):
print(txt1.read())
question2 = raw_input("Do you want me to read just the first line? ")
if (question2 == "yes" or question2 == "Yes"):
print(txt1.readline())
Thanks in advance.