Possible Duplicate:
Learn Python the Hard Way Exercise 17 Extra Question(S)
In this exercise I have to rewrite the code in one line. I tried to write the lines of code like this(from sys import argv,from os.path import exists) but it gives me a syntax error. So, I’m very curious, how can I write this exercise on one line?
Here is the code from the book:
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print "Copying from %s to %s" % (from_file, to_file)
indata = open(from_file).read()
print "The input file is %d bytes long" % len(indata)
print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
raw_input()
output = open(to_file, 'w')
output.write(indata)
print "Alright, all done."
output.close()
Use
;to separate statements instead of,.I don’t think the purpose of the exercise is simply concatenating the lines and separating them with a semicolon. You should try to actually minimize the code.
For example:
Can be replaced with: