Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f = open('./todo.txt', 'r')
- newF = open('./todo-run.txt', 'a')
- lines = f.readlines()
- cLine = lines[int(index) - 1]
- for line in lines:
- if line != cLine:
- newF.write(line)
- f.close()
- newF.close()
- os.remove('./todo.txt')
- shutil.move('./todo-run.txt', './todo.txt')
- sed -i '18 d' filename
- f = open(filepath, 'r')
- lines = [line.rstrip('n') for line in f if not <CONDITION>]
- f.close()
- f.open('filepath, 'w')
- f.write('n'.join(lines))
- f.close()
- def cutfile(file, startcut, endcut):
- file.seek(endcut)
- dataafter=file.read()
- file.seek(startcut)
- file.write(dataafter)
- file.truncate()
- f = open('todo.txt', 'r+')
- line_index = 0
- prev_line_head = 0
- remove_line_index = 3
- move_lines = False
- while True:
- line_head = f.tell()
- line = f.readline()
- if line == '': #EOF
- f.seek(prev_line_head)
- f.truncate()
- break
- if move_lines:
- f.seek(prev_line_head)
- f.write(line)
- f.flush()
- line_head = f.tell()
- line = f.readline() # read past the line we already read to start this iteration
- elif line_index == remove_line_index:
- move_lines = True
- prev_line_head = line_head
- line_index += 1
- f.close()
Add Comment
Please, Sign In to add comment