I need to write a code that imports a list of files then goes through each file and rewrites only half the file. Cutting off the file at a key word. If I can make my code print the half I need I can make it write new files with the needed information. I am able to read the lines of each file and index the word I am using as the spliting spot but I am unsure where to go from here. I need to figure out how to print everything after the word "END"
Weird syntax. I use c# and it is just a call to index of. That is what I used for [my program that I'm blatantly violating the rules promoting here]. Yes, loop and check each lines return code to see if it found the string your searching. If it didn't find it just do nothing and let the loop continue. Else just get the start position of the string you need and then split on that position. Its easy.
that imports a list of files then goes through each file and rewrites only half the file. Cutting off the file at a key word. If I can make my code print the half I need I can make it write new files with the needed information. I am able to read the
by Ezzaral: Advertising/promotion is not permitted in the tech forums.
Does anyone know how to use similar code to split my file but while keeping the line your are spliting from. Right now the code pyTony suggested splits my file at 'END' but does not keep the line with 'END' in it. So I need to figure out how to split after 'END' while still keeping that line.
I do not understand as split does not remove the line split value is. If you want to keep the END in text you just concatenate it to end of first or beginning of next part. You might want to check the partition method if you liked to use that.
for (count, aFileName) in enumerate(files):
filename = aFileName.split('/')
for line in keep:
using this code for some reason it leaves out the line obtaining "END" and I would like it to have the ability to print everything past that line and everything before that line including that line.