Skip to content

Instantly share code, notes, and snippets.

@santosadrian
Created February 3, 2020 16:24
Show Gist options
  • Save santosadrian/3dfe166e592beea72a5608ea85a10b2f to your computer and use it in GitHub Desktop.
Save santosadrian/3dfe166e592beea72a5608ea85a10b2f to your computer and use it in GitHub Desktop.
Example 16
from sys import argv
script, filename = argv
print(f"We're going to erase {filename}.")
print("If you don't want that hit CTRL-C {^C}.")
print("If you do not want that, hit RETURN.")
input("?")
print("Opening the file...")
target = open(filename, 'w')
print("Truncating the file. Goodbye!")
target.truncate()
print("Now I'm going to ask you for three lines")
line1 = input("line 1: ")
line2 = input("line 2: ")
line3 = input("line 3: ")
print("I'm going to write these to the file.")
target.write(f"{line1}\n{line2}\n{line3}\n")
print("And finally, we close it.")
target.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment