Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # [python - Finding a specific keyword while dividing the large csv into smaller segments, and moving to next row until keyword is found - Stack Overflow](https://stackoverflow.com/questions/78555996/finding-a-specific-keyword-while-dividing-the-large-csv-into-smaller-segments-a)
- other_list = [] # for lines
- index = 0 # for filenames
- with open("combined.con") as infile:
- for line in infile:
- other_list.append(line)
- if len(other_list) >= 5 and line.startswith('END'):
- with open(f"Contingency_{index}.con", 'w') as outfile:
- for item in other_list:
- outfile.write(item)
- index += 1
- # clear list for next file
- other_list = []
- # make sure there is no data (without `END` in last line)
- if len(other_list) > 0:
- with open(f"Contingency_{index}.con", 'w') as outfile:
- for item in other_list:
- outfile.write(item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement