Hi, I'm very new to python and I need your help guys.
I want to know if it's possible to "split" file (with regex ?), read the line and make a comparison and then recreate the hole file.
See this, it's the kind of file I need to split. The regex would be "/##/" (so a "block" would be the first line (include) to the 5th line (exclude))
For now I need to "split" the file into "block", but I really don't know how to do that...
I tried this :
I want to know if it's possible to "split" file (with regex ?), read the line and make a comparison and then recreate the hole file.
See this, it's the kind of file I need to split. The regex would be "/##/" (so a "block" would be the first line (include) to the 5th line (exclude))
Output:/##/PARAM/XX/YY/ZZ/X/N/N/N
/##/
/donnee1/XXXXXXXX
/donnee2/A
...
/##/
/donnee1/YYYYY
/donnee2/B
...
After spliting the file to get block, I'll need to compare the line of each block (so one by one) and read the line of a CSV file and compare. If a condition is true, I want to add a line of replace one precise line (but this is another story...)For now I need to "split" the file into "block", but I really don't know how to do that...
I tried this :
files = open(file,'r').read().split('/##/') names = ['file'+ str(num) for num in range(len(files))] for num,file in enumerate(files): open(names[num],'w').write(file)but this is not what I want (it's creating every file from any "/##/" and removing it on every file created, include the first one which doesn't have to be removed /##/PARAM/XX/YY/ZZ/X/N/N/N)"