Python treats non-breaking space wrong?

Discussion in 'Python' started by magnus.lycka@gmail.com, Jun 5, 2010.

  1. Guest

    It seems that Python treats non-breaking space (\xa0) as a normal
    whitespace character, e.g. when splitting a string. See below:

    >>> s='hello\xa0there'
    >>> s.split()

    ['hello', 'there']

    Surely this is not intended behaviour?
    , Jun 5, 2010
    #1
    1. Advertising

  2. On Sat, 05 Jun 2010 01:30:40 -0700, wrote:

    > It seems that Python treats non-breaking space (\xa0) as a normal
    > whitespace character, e.g. when splitting a string. See below:
    >
    >>>> s='hello\xa0there'
    >>>> s.split()

    > ['hello', 'there']
    >
    > Surely this is not intended behaviour?



    Yes it is.

    str.split() breaks on whitespace, and \xa0 is whitespace according to the
    Unicode standard. To put it another way, str.split() is not a word-
    wrapping split. This has been reported before, and rejected as a won't-
    fix.

    http://mail.python.org/pipermail/python-bugs-list/2006-January/031531.html



    --
    Steven
    Steven D'Aprano, Jun 5, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    351
    Olaf Studt
    Dec 3, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,605
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    967
    Steve Lamb
    Oct 23, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    695
    Michael Hudson
    Oct 24, 2003
  5. WLY

    Error with a non-breaking space in WML

    WLY, Feb 25, 2006, in forum: ASP .Net Mobile
    Replies:
    1
    Views:
    154
    intiratr
    Feb 27, 2006
Loading...

Share This Page