I have a very long text file that I want to split into smaller files. It looks like:***200302 abcdfg ***200303 fasafafd ***200304 dajhskjsd
I want that the contents between *** are saved as a new file of the type (1.txt, 2.txt, 3.txt...)
I have tried without success the suggestions posted in another discussion thread (How can I split a text file into multiple text files using python?)
I have also tried to use the code below which showed error.The error is in line 6 (SyntaxError: unexpected character after line continuation character).
with open ('filename.txt','r') as fo:
op=''
start=0
cntr=1
for x in fo.read().split(*\n*):
if (x=='***'):
if (start==1):
with open (str(cntr)+'.txt','w') as opf:
opf.write(op)
opf.close()
op=''
cntr+==1
else:
start=1
else:
if (op==''):
op = x
else:
op=op + '\n' + x
fo.close()