On Tue, Feb 17, 2015 at 12:43 PM, Danny Yoo <d...@hashcollision.org> wrote:
[...] > Ah ha. Escape characters. I see what you mean. :P > > > Just to add: there is a "raw" string literal syntax that will turn off > escape sequence handling. Using a raw string literal may make it > easier to type the value in question. > > We can use raw literal strings by prepending a 'r' in the front of the > string literal. e.g.: > > ########################################## >>>> x = r''' > ... this\ > ... is\ > ... a/ > ... test\ > ... ''' >>>> x > '\nthis\\\nis\\\na/\ntest\\\n' >>>> print x > > this\ > is\ > a/ > test\ > ########################################## Actually, that is the solution I recommended to my son to use. > It might be that the question is trying to motivate the use of raw > string literals, or teaching about escape sequences. I don't have the > book, so I can't say for sure. At this point in the text he is not talking about raw literal strings. I examined the author's source and he has obviously inserted at least one space between each use of a backslash at the end of a line and the EOL terminating characters. He did not do this with the "Game" portion of the code, which did not make any use of "\" . When the file is run everything behaves as desired. But if, as my son did, you leave no spaces between the last backslash and the EOL termination characters, then the problem behavior occurs. Actually, I realize I have a question: If I do the following in the Win7 command line Python interpreter: Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print(""" ... boB\ ... Stepp ... """ ... ) boB\ Stepp Here I placed exactly one space between "\" and where I pressed "Enter". This would be the Game Over 2.0 desired behavior. However, if I bring up the IDLE Python interpreter and do the exact same thing: Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> print(""" boB\ Stepp """ ) boBStepp it gives the undesired behavior. I typed exactly the same character sequences, though IDLE displayed things slightly differently, e.g., the command line interpreter put in "..." in several places, where the IDLE interpreter did not. I am currently scratching my head on these differences, and am currently guessing that IDLE implements the Python interpreter somewhat differently than the implementation that occurs in the Windows command line. Do you have an explanation for these differences? -- boB _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor