Miyago147852

Q4.py

Apr 14th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. path='./Q4.txt'
  2.  
  3. def write():
  4.     file.write('使用者輸入A')
  5.  
  6. def cut():
  7.     x=int(input())
  8.     length=len(file.read())
  9.     file.truncate(length-x)
  10.  
  11. def move():
  12.     x=int(input())
  13.     file.seek(-x-1,2)
  14.     tmp=file.readline()
  15.     file.seek(1,0)
  16.     file.write(tmp)
  17.     length=len(file.read())
  18.     file.truncate(length-x)
  19.  
  20. def point():
  21.     file.seek(1,0)
  22.  
  23. def wq():
  24.     for x in range(3):
  25.         print('.')
  26.     print('Saved!')
  27.     print(file.read())
  28.  
  29. def switcher(keyin):
  30.     d={
  31.         'A': write,
  32.         'B': cut,
  33.         'C': move,
  34.         'D': point,
  35.         'E': wq
  36.     }
  37.     d.get(keyin)()
  38.  
  39. with open(path,'r+',encoding='utf8') as file:
  40.     while True:
  41.         s=input()
  42.         switcher(s)
  43.         if s=='E':
  44.             break
Advertisement
Add Comment
Please, Sign In to add comment