I’m learning Python using Learn Python The Hard Way. It is very good and efficient but at one point I had a crash. I’ve searched the web but could not find an answer.
Here is my question:
One of the exercises tell to do this:
from sys import argv
script, filename = argv
and then it proceeds to doing things that I do understand:
print "we are going to erase %r." % filename
print "if you don't want that, hit CTRL-C (^C)."
print "if you do want that, hit RETURN."
raw_input("?")
print "opening the file..."
target = open(filename, 'w')
What does the first part mean?
P.S. the error I get is:
syntaxError Unexpected character after line continuation character
This is unpacking the sequence
argv. The first element goes intoscript, and the second element goes intofilename. In general, this can be done with any iterable, as long as there exactly as many variables on the left-hand-side as are items in the iterable on the right-hand-side.The code you show seems ok, I don’t know why you are getting a syntax-error there.