The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by tselkow]

Hi,

This is just a by-the-by that the examples at the top of the page only display
properly in the command line window of 1.6a2. In the IDLE the command is
echeoed back with 11 at the beginning when using print, and in the second
() shows up.

Regards,

T. Selkow
import-bot (20211) [Avatar] Offline
#2
Re: Examples page 46
[Originally posted by daryl harms]

Hi Tom,

I believe what you are seeing is the that when evaluating a string in
interactive mode, it will be displayed with its special characters shown as
octal escape sequences (in order to make clear what characters are actually in
the string). For this example:

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
IDLE 0.5 -- press F1 for help
>>> x = " This string starts with a "tab"."
>>> x
'11This string starts with a "tab".'

The tab character is shown as octal 011. Its only when using the print
statement that it will actually be acted on:

>>> print x
This string starts with a "tab".

This is explained in section 7.3.3 on page 70. But that doesn't help much when
you are on page 46 smilie

This shouldn't change in Python 1.6:

Python 1.6a2 (#0, Apr 6 2000, 11:45:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
IDLE 0.6 -- press F1 for help
>>> x = " This string starts with a "tab"."
>>> x
'11This string starts with a "tab".'
>>> print x
This string starts with a "tab".



Similarily (for the second example), any backslash character in a string will
be displayed in interactive mode as a double backslash (the way you have to
enter it) but will only have one backslash in it as seen when doing any
operation on it (like using a print command).

I hope this helps. I see that this is confusing. Either this behavior should
have been explained here or these specific examples shouldn't have been used
at this point in the book.

Daryl
import-bot (20211) [Avatar] Offline
#3
Re: Examples page 46
[Originally posted by daryl harms]

We have problem here in that the posting software for this forum,
unfortunately, "eats" backslashes and sometimes the following characters (I
would guess taking them as escape characters itself). So:

>>> x = "This string starts with a "tab"."

In the above line there was a backslash-t before 'This' and a backslash before
each of the quotes around 'tab' (as in the example on page 46)

>>> x
> '11This string starts with a "tab".'

In the above line there was a backslash-0 in front of the 11.

Hopefully, the following will be what it should look like:

>>> x = " This string starts with a "tab"."
>>> x
'11This string starts with a "tab".'


Daryl