Note that there are some explanatory texts on larger screens.

plurals
  1. POTotal Python Noob: why doesn't this work?
    primarykey
    data
    text
    <p>I'm working through Learn Python the Hard Way, and trying to <em>understand</em> it rather than just hammer away. I got stuck on Exercise 16, as discussed already on SO here: </p> <p><a href="https://stackoverflow.com/questions/6394170/very-basic-python-question-strings-formats-and-escapes">Very basic Python question (strings, formats and escapes)</a></p> <p>but I'm still trying to figure out why this approach does not work: </p> <pre><code>from sys import argv script, filename = argv print "Attempting to open the file now." print open(filename).read() print "We're going to erase %r." % filename print "If you don't want that, hit CTRL-C." print "If you do want that, hit RETURN." raw_input("?") print "Opening the file..." target = open(filename, 'w') print "Truncating the file. Goodbye!" target.truncate() print "Now I'm going to ask you for three lines." line1 = raw_input("line 1: ") line2 = raw_input("line 2: ") line3 = raw_input("line 3: ") print "I'm going to write these to the file." linebreak = "\n" target.write("%s %s %s %s %s %s") % (line1, linebreak, line2, linebreak, line3, linebreak) target.write("the ending line") print "And finally, we close it." target.close() </code></pre> <p>I've established a value for linebreak, and am calling the line1, line2 and linebreak values with %s in the target.write command. Should't it parse as "line1 \n line2 \n line3 \n" when it's read? </p> <p>This is probably the equivalent of being asked by a child what keeps the sky up or something, and I apologize for being kind of thick. Thanks! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload