Skip to content

Instantly share code, notes, and snippets.

@pyohei
Created March 2, 2019 08:48
Show Gist options
  • Save pyohei/74390df1428bdc61b330e6ebd51e97d8 to your computer and use it in GitHub Desktop.
Save pyohei/74390df1428bdc61b330e6ebd51e97d8 to your computer and use it in GitHub Desktop.
Separate combined text file.
"""This text contain `----fileName` as break point."""
FILE_NAME = 'all.txt'
with open(FILE_NAME, mode='r') as f:
_f = None
for line in f.readlines():
if line.startswith('----'):
if _f:
_f.close()
_file_name = line.lstrip('-').rstrip('\r\n')
_f = open('test/' + _file_name, 'w')
else:
_f.write(line)
if _f:
_f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment