whitespace and ?asc()?

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Jul 1 22:38:13 EDT 2003


>>>>> "Ray" == Ray Tomes <rtomes at ihug.co.nz> writes:

    Ray> Hi all I am totally new to python. On the whole I really like
    Ray> the design of the language and after just one day may be
    Ray> considered a convert.

Welcome.

    Ray> I was trying to find out the exact definition of whitespace
    Ray> so I went to look at strings.whitespace to find out which
    Ray> chars were whitespace, and found 9, 10, 11, 12, 13, 32 which
    Ray> according to my ancient ascii chart are TAB, LF, VT, NP, CR,
    Ray> SPACE. Anyone know what NP = 12 is?

NP = New Page

    Ray> Also, in trying to find the ASCII (or is it ANSI) values for
    Ray> characters I could not find the reverse function for chr()
    Ray> [in BASIC it is asc()]- can someone please tell me what
    Ray> reverses chr()?

ord

    Ray> I had to do this yucky thing to decode whitespace ...

If you have a relatively recent version of python (2.0 or later),
perhaps you'll find this less yucky ...
 
  print [ord(c) for c in string.whitespace] 

This makes use of list comprehensions, which are often a cleaner and
faster way of writing simple combinations of 'for' loops and 'if'
statements:

  http://www.python.org/peps/pep-0202.html
  http://www.amk.ca/python/2.0/index.html#SECTION000600000000000000000

Cheers,
John Hunter





More information about the Python-list mailing list