Guest User

Untitled

a guest
Jul 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. f = open('./todo.txt', 'r')
  2. newF = open('./todo-run.txt', 'a')
  3. lines = f.readlines()
  4. cLine = lines[int(index) - 1]
  5.  
  6. for line in lines:
  7. if line != cLine:
  8. newF.write(line)
  9. f.close()
  10. newF.close()
  11. os.remove('./todo.txt')
  12. shutil.move('./todo-run.txt', './todo.txt')
  13.  
  14. sed -i '18 d' filename
  15.  
  16. f = open(filepath, 'r')
  17. lines = [line.rstrip('n') for line in f if not <CONDITION>]
  18. f.close()
  19. f.open('filepath, 'w')
  20. f.write('n'.join(lines))
  21. f.close()
  22.  
  23. def cutfile(file, startcut, endcut):
  24. file.seek(endcut)
  25. dataafter=file.read()
  26. file.seek(startcut)
  27. file.write(dataafter)
  28. file.truncate()
  29.  
  30. f = open('todo.txt', 'r+')
  31. line_index = 0
  32. prev_line_head = 0
  33. remove_line_index = 3
  34. move_lines = False
  35. while True:
  36. line_head = f.tell()
  37. line = f.readline()
  38.  
  39. if line == '': #EOF
  40. f.seek(prev_line_head)
  41. f.truncate()
  42. break
  43.  
  44. if move_lines:
  45. f.seek(prev_line_head)
  46. f.write(line)
  47. f.flush()
  48. line_head = f.tell()
  49. line = f.readline() # read past the line we already read to start this iteration
  50. elif line_index == remove_line_index:
  51. move_lines = True
  52. prev_line_head = line_head
  53. line_index += 1
  54. f.close()
Add Comment
Please, Sign In to add comment