-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
35 lines (24 loc) · 806 Bytes
/
Copy pathparser.py
File metadata and controls
35 lines (24 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
class Section:
def __init__(self, name, contents):
self.name = name
self.contents = contents
# maps dictionary accesses to attributes: section['name'] -> section.name
def __getitem__(self, index):
return getattr(self, index)
class Star:
def __init__(self):
self.sections = []
self.name = ''
def add_section(self, name, body):
self.sections.append(Section(name, body))
def cleanup_name(name):
last, first = name.split(',')
return first + ' ' + last
def parse_star(star_file):
lines = star_file.readlines()
star = Star()
star.name = cleanup_name(lines[1])
star.add_section("Section One", "Contentz")
star.add_section("Section Two", "Contentzz")
return star