line break confusion

Tim Roberts timr at probo.com
Sun Feb 17 07:32:49 CET 2002


Piet van Oostrum <piet at cs.uu.nl> wrote:

>>>>>> Michael Mell <mike at nthwave.net> (MM) writes:
>
>MM> In the string module, whitespace = ' \t\n\r\v\f' (5 characters here).
>MM> Yet, when I run this:
>>>>> import string
>>>>> for c in string.whitespace:
>>>>> print '.'+ c + '.'
>
>MM> I get 7 results.
>MM> What's going on here?
>
>And then you will get more lines than 6. The \n, \v and \f will probably
>get two dots on separate lines each. The \r will rpobably print one dot
>only because the second dot overprints the first one. So you should get 11
>dots together.

I think you've nailed his 6 vs 7 problem:

C:\Tmp>python
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> string.whitespace.encode('hex')
'090a0b0c0d20'
>>> for c in string.whitespace:
...  print '.' + c + '.'
...
.       .      # \i
.              # \n part 1
.              # \n part 2
.?.            # \v, which prints as a male symbol in Windows
.?.            # \f, which prints as a female symbol in Windows
.              # \r, two dots overprinted
. .            # good old space
>>>

--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list