-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex15.py
64 lines (47 loc) · 1.17 KB
/
ex15.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from sys import argv
script, filename = argv
txt = open(filename)
print(f"Here's your {filename} file")
print(txt.read())
print("Type the filename again: ")
file_again = input('> ')
txt_again = open(file_again)
#print message from ex15_sample.txt again
print(txt_again.read())
#txt.close()
#txt_again.close()
print(f"We're going to erase {filename}")
print("If you don't want this, hit CTRL-C (^C).")
print("If you want this, hit RETURN.")
input("?")
print("Open 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("line1: ")
line2 = input("line2: ")
line3 = input("line3: ")
print("I'm going to write these to the file")
#target.write(line1)
#target.write("\n")
#target.write(line2)
#target.write("\n")
#target.write(line3)
#target.write("\n")
target.write(f"""
{line1}
{line2}
{line3}
""")
print(f"""
{line1}
{line2}
{line3}
""")
print("And finally, we're close it.")
target.close()
print("Type the new file here: ")
newfile = input('>>> ')
opennewfile = open(newfile)
print(opennewfile.read())