Skip to content

Instantly share code, notes, and snippets.

@gary-liguoliang
Created February 27, 2017 14:08
Show Gist options
  • Save gary-liguoliang/2546918d426bccdbe75b8f0b3391147b to your computer and use it in GitHub Desktop.
Save gary-liguoliang/2546918d426bccdbe75b8f0b3391147b to your computer and use it in GitHub Desktop.
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