Skip to content

Commit 47cfdc7

Browse files
authored
Added file editing
1 parent c422373 commit 47cfdc7

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import os.path
23
import time
34

45
def process():
@@ -9,18 +10,27 @@ def process():
910
if lines == "exit-editor\n":
1011
break
1112
else:
12-
fo.seek(0)
1313
fo.writelines(lines)
1414

1515
if __name__ == "__main__":
1616
print("Welcome to Python-Notepad! Made with <3 by WilliamAfton-codes\n")
1717

1818
filename_input = str(input("What would you like the file to be called?: "))
19-
ext_input = str(input("What would you like the extension to be? (Don't type the '.'): "))
19+
print("Don't type the '.' in the extension")
20+
ext_input = str(input("What would you like the extension to be? (Leave blank to default to .txt): "))
21+
if ext_input == "":
22+
ext_input = "txt"
23+
else:
24+
pass
2025
filename = filename_input + "." + ext_input
26+
27+
file_exists = os.path.exists(filename)
28+
if file_exists == True:
29+
print("A file with this name in this directory already exists, Python-Notepad will add text to the end")
30+
2131
fo = open(filename, "a")
2232

2333
print("Loading text editor...")
2434
time.sleep(1)
2535
print("\nType 'exit-editor' to stop writing.")
26-
process()
36+
process()

0 commit comments

Comments
 (0)