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?
dat file to a CSV file in Python in four simple steps: (1) Install the Pandas library, (2) import the Pandas library, (3) read the CSV file as DataFrame, and (4) write the DataFrame to the file.
Most DAT files contain text, so you can open them with text editors, like Notepad, Notepad++, VS Code, and so on. If you are sure the information contained in the DAT file is a video or audio, then your media player can open it. If it's a PDF, then Adobe Reader can open it, and so on.
Python3. In this method we will import the csv library and open the file in reading mode, then we will use the DictReader() function to read the data of the CSV file. This function is like a regular reader, but it maps the information to a dictionary whose keys are given by the column names and all the values as keys.
for line in open(filename, 'r'):
item = line.rstrip() # strip off newline and any other trailing whitespace
...
For the bonus: Tennis!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With