-1

I have a csv file with the following format.

//Course times
CSE110, Mon, 1:00 PM, Fri, 1:00 PM
CSE114, Mon, 8:00 AM, Wed, 8:00 AM, Fri, 8:00 AM
....

//Course recitation times
CSE306, Mon, 2:30 PM
CSE307, Fri, 4:00 PM
...

//class strength
CSE101, 44, yes
CSE101, 115, yes
...

I need to parse and store all of these in separate data structures. What could be the right reg-ex patterns for each of the category? or is there any other way?

raghu
  • 131
  • 3
  • 13
  • 1
    If its a comma delimited list that is always the same set of data you could read it without Regex. – marsh Mar 18 '15 at 23:00
  • 1
    If there are other lines mixed in you could use `line.startswith("CSE")` i.s.o. regex. And yes, the comma-separated list is easier to deal with using `split(',')` than usingregex. – emvee Mar 18 '15 at 23:01
  • [Reference](http://stackoverflow.com/questions/29132845/choosing-right-data-structure-to-parse-a-file) – Celeo Mar 18 '15 at 23:20

1 Answers1

0

You should really be using the python csv module for this:

""" Assume separate files
//Course times
CSE110, Mon, 1:00 PM, Fri, 1:00 PM
CSE114, Mon, 8:00 AM, Wed, 8:00 AM, Fri, 8:00 AM
"""
with open('course_times.csv') as fin_:
    fin = csv.reader(fin_)
    # further processing here

# process other files
hd1
  • 33,938
  • 5
  • 80
  • 91