2014-10-02 42 views
2

这里是代码:我不能摆脱 xa0在这个字符串中使用python?

shipping_info = u'Expedited (2-3 Bus. Days)\xa0($17.99)' 

我不能让它使用像用替换法更换\ XA0。

这里是我的尝试:

x.replace('\\xa0', ' ') 
x.replace(')\xa0(', " ") 
x.replace(unichr(160), " ") 
+1

记住'replace'不起作用原地的,你必须分配结果。 'x = x.replace(...)'。 – 2014-10-02 14:53:38

回答

3

使用Unicode文本指定u'\xa0'

>>> shipping_info = u'Expedited (2-3 Bus. Days)\xa0($17.99)' 
>>> shipping_info.replace(u'\xa0', u' ') 
u'Expedited (2-3 Bus. Days) ($17.99)' 
+0

'u'...''v.s. ''...'' – 2014-10-02 14:50:13

+0

你在ipython中试过这个吗?我试过这个..不工作..?你可以试试吗? – slopeofhope 2014-10-02 15:04:08

+0

@slopeofhope,当然,我尝试过。 http://asciinema.org/a/12634 – falsetru 2014-10-02 15:06:12

相关问题