Created
February 27, 2017 14:08
-
-
Save gary-liguoliang/2546918d426bccdbe75b8f0b3391147b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def further_process(file_name): | |
print 'processing :%s' % file_name | |
print 'processing: file: %s' % file_name | |
def split_to_files(s, split_start_with, split_end_with, func): | |
cursor = 0 | |
while cursor >= 0: | |
try: | |
cursor = s.index(split_start_with, cursor + 1) | |
print s[cursor: s.index(split_end_with, cursor) + len(split_end_with)] | |
func(s[cursor: s.index(split_end_with, cursor) + len(split_end_with)]) | |
except ValueError as e: | |
print 'end: ', type(e) | |
break | |
if __name__ == '__main__': | |
s = """ | |
<Package> | |
<item>item1</item> | |
<item>item2</item> | |
<item>item3</item> | |
</Package> | |
""" | |
print s | |
split_to_files(s, '<item>', '</item>', further_process) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment