Created
October 28, 2020 12:10
-
-
Save bvcelari/e02f69ff548db9310c4ac7e3fe1ebb93 to your computer and use it in GitHub Desktop.
jcasc split
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
file1 = open('test-suite-casc-yaml.txt', 'r') | |
filename = '' | |
filecontent = [] | |
line = file1.readline() | |
while True: | |
# if line is empty | |
# end of file is reached | |
if not line: | |
break | |
if '---\n' in line and len(line) == 4: | |
if filename != '': | |
print 'Creating: '+filename | |
with open(filename, 'w') as writer: | |
for i in filecontent: | |
writer.write(i) | |
#if filename is not empty, we need to close the file where we are writting | |
writer.close() | |
filecontent = [] | |
filename = '' | |
else: | |
line = file1.readline() | |
filename = line.split('# ')[1].rstrip() | |
else: | |
line = file1.readline() | |
filecontent.append(line) | |
with open(filename, 'w') as writer: | |
for i in filecontent: | |
writer.write(i) | |
writer.close() | |
file1.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment