Created
April 21, 2014 10:22
-
-
Save brickgao/11138647 to your computer and use it in GitHub Desktop.
不用自动化问卷系统的人生
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
_file_list = os.listdir(u'./data') | |
_cnt = 0 | |
for _file_name in _file_list: | |
_cnt += 1 | |
print str(_cnt) + u' start to analyse ' + _file_name | |
with open(os.path.join(u'./data', _file_name), 'r') as _file: | |
with open(u'sheet1.txt', 'a') as _output_1: | |
while True: | |
_line = unicode(_file.readline()[:-1], 'utf-8') | |
if u'调查表1' in _line: | |
break | |
while True: | |
_line = unicode(_file.readline()[:-1], 'utf-8') | |
if u'调查表2' in _line: | |
break | |
if not u'(' in _line: | |
continue | |
_flag = False | |
for _ in _line: | |
if _flag and _ != u' ': | |
_output_1.write((_ + u'\t').encode('utf-8')) | |
break | |
if _ == u'(': | |
_flag = True | |
_output_1.write('\n') | |
_output_1.close() | |
with open(u'sheet2.txt', 'a') as _output_2: | |
while True: | |
_line = unicode(_file.readline()[:-1], 'utf-8') | |
if u'调查表3' in _line: | |
break | |
_flag = False | |
if not u'(' in _line and not u'(' in _line: | |
continue | |
for _ in _line: | |
if _flag and _ != u' ': | |
_output_2.write((_ + u'\t').encode('utf-8')) | |
break | |
if _ == u'(' or _ == u'(': | |
_flag = True | |
_output_2.write('\n') | |
_output_2.close() | |
with open(u'sheet3.txt', 'a') as _output_3: | |
_t = 0 | |
_g_flag = False | |
while True: | |
_line = unicode(_file.readline()[:-1], 'utf-8') | |
if u'调查表4' in _line: | |
break | |
if not u'√' in _line: | |
continue | |
if u'√' in _line and not _g_flag: | |
_g_flag = True | |
continue | |
if u'√' in _line: | |
_t += 1 | |
_index = _line.find(u'√', 0) | |
_output_3.write((_line[_index - 2:_index] + '\t').encode('utf-8')) | |
print 'total: ' + str(_t) | |
_output_3.write('\n') | |
_output_3.close() | |
with open(u'sheet4.txt', 'a') as _output_4: | |
_g_flag = False | |
while True: | |
_line = unicode(_file.readline()[:-1], 'utf-8') | |
if u'产前或者产后您有回过娘家吗' in _line: | |
break | |
if not _g_flag and u'1' in _line: | |
_g_flag = True | |
if not _g_flag: | |
continue | |
if not u'(' in _line: | |
continue | |
_flag = False | |
for _ in _line: | |
if _flag and _ != u' ': | |
_output_4.write((_ + '\t').encode('utf-8')) | |
break | |
if _ == u'(': | |
_flag = True | |
_output_4.write('\n') | |
_output_4.close() | |
_file.close() | |
print _file_name + ' done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment