7

I am making a basic program that has a quiz with multiple choice answers. I want to access the data from the .DAT file. Here's the basic layout of the .DAT file.

Which sport uses the term LOVE ?
Tennis
Golf
Football
Swimming
A

How can I access each line separately?

1

1 Answer 1

13
for line in open(filename, 'r'):
    item = line.rstrip() # strip off newline and any other trailing whitespace
    ...

For the bonus: Tennis!

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry i'm quite new to python. What does the 'r' do? Thanks
'r' tells open that you want to open the file as "read" as opposed to write, read binary, etc. see docs.python.org/2/library/functions.html#open

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.