Exercise17 "More Files" LPTHW

We’re asked to shorten the script… this is what I got thus far… Am I still able to make it one line regardless?

import sys
from os.path import exists
script, from_file, to_file = sys.argv

#one liner???
if exists(to_file) == True:
print(f"Copying {to_file} with {from_file}\a")
with open(from_file) as in_file:
indata = in_file.read()
out_file = open(to_file, ‘w’)
out_file.write(indata)
out_file.close()
in_file.close()

#this is about the shortest I am able to get it. But if I’m able to shorten it, any suggestions or tips would help

I believe you emailed me, but here’s some quick clues:

open(to_file, 'w').write(in_file.read())

Also, you can put these tags around your code to get formatting:

[code]
open(to_file, 'w').write(in_file.read())
[/code]
1 Like