Hello! Vidallia here. I've been learning Modern Python aka Python3. So to test my skills from what I know as of no I made a simple command line text editor and file copier script. It's probably coded with a lot of bad practices so try not to laugh too hard! I'm sharing this in the hopes someone else that's in my shoes (learning Python) can get something out of this!
#Text Edit v0.0.2 by V1
#Quick and Dirty script to either copy or create and write a file.
#More features to come.
from sys import argv
script = argv
print(f"\tWelcome to {script}.")
def copy_a_file():
print("To copy a file. Give me the filename.")
file = input(">> ")
oldfile = open(file).read()
print("Now, what do you want the new file called.")
nfile = input(">> ")
newfile = open(nfile, 'w')
newfile.write(oldfile)
print(f"You have made a copy of {file} and named it {nfile}")
oldfile.close()
newfile.close()
def create_a_new():
print("A new file will be created. Give me the name:")
file = input(">> ")
print("Press 1 to create or 2 to create and write: ")
choice = input(">> ")
if choice == "1":
newfile = open(file, 'w')
newfile.close()
elif choice == "2":
newfile = open(file, 'w')
print(f"{file} was created")
print("Press enter to write multiple lines.")
print("If the number '1' is given the loop will end.")
while True:
text = input(">> ")
if text == "1":
print("Thank you. File saved")
newfile.close()
quit()
else:
newfile.write(f"{text}\n")
#This section below is a quick and dirty implementation
print("Type 1 to copy a file or 2 to create or write a file")
uin = input(">> ")
if uin == "1":
copy_a_file()
elif uin == "2":
create_a_new()
else:
print("Try again")