Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread boB Stepp
On Tue, Feb 17, 2015 at 3:34 PM, Joel Goldstick
 wrote:
> On Tue, Feb 17, 2015 at 4:05 PM, boB Stepp  wrote:
>> On Tue, Feb 17, 2015 at 1:47 PM, Dave Angel  wrote:
>>> On 02/17/2015 02:12 PM, boB Stepp wrote:

>> This seems to be the case. On a related note, I wanted to copy and
>> paste the author's source code, showing how he generated the large,
>> "Game Over", but my Gmail keeps collapsing the white space, making the
>> result look like gibberish. So far I cannot find a setting to
>> eliminate this undesired behavior. Argh!
>
> Do you have gmail set to plain text mode?
What I just sent out, that showed what I wanted to show, was not plain
text, but Google's fixed-width font. Of course, turning that on took
away plain text mode. I had a couple of years ago or so (Whenever it
was that I started working with Python and interacting with the Tutor
list.) installed the Stylish extension to Gmail and set up a plain
text, fixed width font. Somehow that font has been removed from my
Gmail settings with no known action on my part. I did not notice it
until today when I tried to reproduce the ASCII art under discussion
in this thread and found that I could not.

So apparently I can do plain text, but not fixed width, or I can do
fixed width, but not plain text! At least until I come up with a
solution. Heavy sighs!

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread Joel Goldstick
On Tue, Feb 17, 2015 at 4:05 PM, boB Stepp  wrote:
> On Tue, Feb 17, 2015 at 1:47 PM, Dave Angel  wrote:
>> On 02/17/2015 02:12 PM, boB Stepp wrote:
>>
>> See
>> https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals
>>>
>>>
>>> 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.
>>
>>
>> Then he's teaching you wrong. Backslash followed by space is not a valid
>> escape sequence, and to do it at the end of line is particularly odious.  I
>> wouldn't even suggest it in real code, never mind in something that's
>> published on paper.
>
> I guess I am inclined to cut the author some slack here. The point of
> his example was NOT to teach escape sequences, but instead show how
> using keyboard characters you could create a text picture, in this
> instance of a large "Game Over". He at this point was talking about
> the print function used with quotes and triple quotes. A little bit
> later in this same chapter he talks about escape sequences. The point
> of my original post was to point out that because the author is using
> a backslash as part of his ASCII art, that unintended consequences
> might result. I will admit that I was surprised that the author did
> not think of this potential issue and warn the reader of possible
> problems, especially as the book is aimed at total beginners. But I
> suppose it is difficult to anticipate all possible problems. But sure
> enough, my son stumbled into this one!
>
> [...]
>
>> I would never intentionally make any trailing whitespace in source code be
>> significant.  And years ago I used an editor that routinely deleted any such
>> invisible characters.  From the rest of your message, it looks like IDLE may
>> have that behavior.
>
> This seems to be the case. On a related note, I wanted to copy and
> paste the author's source code, showing how he generated the large,
> "Game Over", but my Gmail keeps collapsing the white space, making the
> result look like gibberish. So far I cannot find a setting to
> eliminate this undesired behavior. Argh!

Do you have gmail set to plain text mode?
> --
> boB
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



-- 
Joel Goldstick
http://joelgoldstick.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread boB Stepp
On Tue, Feb 17, 2015 at 3:05 PM, boB Stepp  wrote:
> This seems to be the case. On a related note, I wanted to copy and
> paste the author's source code, showing how he generated the large,
> "Game Over", but my Gmail keeps collapsing the white space, making the
> result look like gibberish. So far I cannot find a setting to
> eliminate this undesired behavior. Argh!
​
​I have found the problem. During some previous update or other
Google-induced behavior, all of the work I did to have a specific
fixed-width ​font with an extension has apparently been undone. Anyway,
here is the snippet of the author's source code that I had intended to send
earlier:

​
print(
"""
 _   ___   ___  ___   _
/  ___| /   | /   |/   | |  ___|
| |/ /| |/ /|   /| | | |__
| |  _/ ___ |   / / |__/ | | |  __|
| |_| |  / /  | |  / /   | | | |___
\_/ /_/   |_| /_/|_| |_|

 _   _ _   _   _
/  _  \ | |   / / |  ___| |  _  \
| | | | | |  / /  | |__   | |_| |
| | | | | | / /   |  __|  |  _  /
| |_| | | |/ /| |___  | | \ \
\_/ |___/ |_| |_|  \_\

"""
 )
​




-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread boB Stepp
On Tue, Feb 17, 2015 at 1:47 PM, Dave Angel  wrote:
> On 02/17/2015 02:12 PM, boB Stepp wrote:
>
> See
> https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals
>>
>>
>> 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.
>
>
> Then he's teaching you wrong. Backslash followed by space is not a valid
> escape sequence, and to do it at the end of line is particularly odious.  I
> wouldn't even suggest it in real code, never mind in something that's
> published on paper.

I guess I am inclined to cut the author some slack here. The point of
his example was NOT to teach escape sequences, but instead show how
using keyboard characters you could create a text picture, in this
instance of a large "Game Over". He at this point was talking about
the print function used with quotes and triple quotes. A little bit
later in this same chapter he talks about escape sequences. The point
of my original post was to point out that because the author is using
a backslash as part of his ASCII art, that unintended consequences
might result. I will admit that I was surprised that the author did
not think of this potential issue and warn the reader of possible
problems, especially as the book is aimed at total beginners. But I
suppose it is difficult to anticipate all possible problems. But sure
enough, my son stumbled into this one!

[...]

> I would never intentionally make any trailing whitespace in source code be
> significant.  And years ago I used an editor that routinely deleted any such
> invisible characters.  From the rest of your message, it looks like IDLE may
> have that behavior.

This seems to be the case. On a related note, I wanted to copy and
paste the author's source code, showing how he generated the large,
"Game Over", but my Gmail keeps collapsing the white space, making the
result look like gibberish. So far I cannot find a setting to
eliminate this undesired behavior. Argh!
-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread Danny Yoo
> Dawson) Game Over 2.0 program in chapter two on page 17. The object of
> this program is to do ASCII-style art to generate a large rendition of
> "Game Over" using the following characters: "_" , "\" , "|" , and "/"
> . When my son tried to do his version, the "Over" portion did not
> print correctly.

Hi boB,


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\
##


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.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread Dave Angel

On 02/17/2015 02:12 PM, boB Stepp wrote:

See 
https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals


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.


Then he's teaching you wrong. Backslash followed by space is not a valid 
escape sequence, and to do it at the end of line is particularly odious. 
 I wouldn't even suggest it in real code, never mind in something 
that's published on paper.


The docs admit that the invalid escape sequences behave differently than 
C, in that the backslash is retained.  I think it should be a syntax 
error to have an invalid sequence.


If the backslash immediately precedes the newline, then the two 
characters both get eaten, and the two lines are combined into one. 
That can be useful if you want to define a string that's too long to fit 
in your source file.


I would never intentionally make any trailing whitespace in source code 
be significant.  And years ago I used an editor that routinely deleted 
any such invisible characters.  From the rest of your message, it looks 
like IDLE may have that behavior.




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.




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread boB Stepp
On Tue, Feb 17, 2015 at 12:43 PM, Danny Yoo  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


[Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."

2015-02-17 Thread boB Stepp
I know that there have been multiple posts in the past about Michael
Dawson's book, "Python Programming for the Absolute Beginner, 3rd
ed.". Because of this I thought I might mention something my son
encountered this morning. I have finally gotten my son to start
working in this book. He came to me with a problem this morning, which
he could not figure out when trying to replicate the author's (Michael
Dawson) Game Over 2.0 program in chapter two on page 17. The object of
this program is to do ASCII-style art to generate a large rendition of
"Game Over" using the following characters: "_" , "\" , "|" , and "/"
. When my son tried to do his version, the "Over" portion did not
print correctly. The top half of "Over" printed first followed by the
second half of the word next to it. I don't want to say too much for
those working through this book, but the essence of the issue is
illustrated by the following:

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
"""
)

boB
Stepp

>>> print(
"""
boB\
Stepp
"""
)

boBStepp

This led to a discussion with my son about the invisible characters
that terminate lines in Window and *nix, escape sequences, etc.
Hopefully this might prove helpful to those starting this book without
just giving the answer if this problem comes up in their efforts.

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor