Skip to content

Instantly share code, notes, and snippets.

@Funk3
Last active October 15, 2017 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Funk3/85cd66eceb0b630c4fea52e3a2de5c81 to your computer and use it in GitHub Desktop.
Save Funk3/85cd66eceb0b630c4fea52e3a2de5c81 to your computer and use it in GitHub Desktop.
Code shortening.
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print(f"Copying from {from_file} to {to_file}")
in_file = open(from_file)
indata - in_file.read()
print(f"The input file is {len(indata)} bytes long")
print(f"Does the output file exist? {exists(to_file)}")
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()
out_file = open(to_file, 'w')
out_file.write(indata)
print("alright, all done.")
out_file.close()
in_file.close()
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print(f"This file is {len(from_file)} bytes long")
print(f"Does the output file exist? {exists(to_file)}")
input("Press enter to write file.")
#you need the variable in order to use the write command
#you cannot run commands inside the write function
#open it in a variable first then you can write it.
f = open(from_file).read()
open(to_file, 'w').write(f)
@Funk3
Copy link
Author

Funk3 commented Oct 15, 2017

haha yeah, I didn't revise it with my latest script. Good catch again.

it just clicked though. it has to be a string in the write() function, so I had to create a variable that would open the file so it can be read from to write into the to_file.

It was a bit weird... but then it clicked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment