A Python parser that takes the content of a text file and then reads into variables

Text-File-Parser

A Python parser that takes the content of a text file and then reads into variables.

Input.text File

1.	What is your ***? 
 
1.	18 - 34 
2.	35- 44 
3.	45- 54 
4.	55-64 
5.	Over 65 
6.	Don't know
 
2.	What *** do you live in? 
 
1.	Ontario
2.	Quebec
3.	Manitoba 
4.	Alberta
5.	Other

Given a plain text file as above, this Python script reads all the questions and their numbers, storing them into two variables for further data analysis. Same operations apply to the answers and their numbers.

Assumption

Assuming each number is followed by a tab character (“t”). And there is a next line (“n”) before and after each question.

Output Screenshot

variables

 

 

 

To finish reading, please visit source site