forked from robot527/python_primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.py
More file actions
32 lines (27 loc) · 678 Bytes
/
sketch.py
File metadata and controls
32 lines (27 loc) · 678 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
""" This a program which used to deal with
the test file called "sketch.txt".
"""
import os
import sys
print(os.getcwd())
#os.chdir('the dir which include the file sketch.txt')
try:
data = open('sketch.txt') #open('not_exist.txt')
except FileNotFoundError:
print('File not found in the current working directory!')
sys.exit()
man = []
other = []
for each_line in data:
try:
(role, spoken) = each_line.split(':', 1)
spoken = spoken.strip()
if role == 'Man':
man.append(spoken)
elif role == 'Other Man':
other.append(spoken)
except ValueError:
pass
data.close()
print(man)
print(other)