Advertisement
nosthemerc

add_line (works now)

Nov 15th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. from sys import argv
  2.  
  3. script, filename = argv
  4.  
  5. print("Opening", filename)
  6. print("""
  7.     Would you like to add lines to %s?
  8.     \n RETURN for yes
  9.     \n ^C for no
  10.     """) % filename
  11. raw_input("...")
  12.  
  13. test_text = open(filename, 'r')
  14. print(test_text.read())
  15.  
  16. print("""
  17.     What would you like to replace this text with?
  18.     Add three lines.
  19.     """)
  20. test_text = open(filename, 'w')
  21. test_text.write(
  22.     raw_input("Line 1: ") + '\n' +
  23.     raw_input("Line 2: ") + '\n' +
  24.     raw_input("Line 3: ") + '\n'
  25.     )
  26. test_text.close()
  27.  
  28. test_text = open(filename, 'r')
  29. print("\n Here is your new file:\n")
  30. print(test_text.read())
  31. test_text.close()
  32.  
  33. print("Hit RETURN to close program.")
  34. raw_input("...")
  35.  
  36. #worked out of an 'IOError: [Errno 0] Error'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement