2007年09月26日 星期三 23:34
str='中秋快乐'
print str.split('快')
但是报错,需要什么特别的语法吗?
2007年09月26日 星期三 23:52
On 9/26/07, OnMyWay <onmyway.q在gmail.com> wrote: > str='中秋快乐' > print str.split('快') > > 但是报错,需要什么特别的语法吗? 变量名不能叫str的原因吧。 >>> r='中秋快乐' >>> r.split('快') ['\xe4\xb8\xad\xe7\xa7\x8b', '\xe4\xb9\x90'] > -- Best Regards, Leo Jay
2007年09月27日 星期四 00:00
>>> str = 'ÖÐÇï¿ìÀÖ'
>>> print str.split('¿ì')
['\xd6\xd0\xc7\xef', '\xc0\xd6']
>>>
û±¨´í¡£
ÓÃstr = u'ÖÐÇï¿ìÀÖ' print str.split(u'¿ì')
¿´¿´°É
On 9/26/07, OnMyWay <onmyway.q在gmail.com> wrote:
>
> str='ÖÐÇï¿ìÀÖ'
> print str.split('¿ì')
>
> µ«ÊDZ¨´í£¬ÐèÒªÊ²Ã´ÌØ±ðµÄÓï·¨Âð£¿
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070927/5a7086a6/attachment.htm
2007年09月27日 星期四 02:23
没报错,是因为你的解释器认为输入默认编码是utf-8 如果是在文本编辑器中,可以在头部加入: #code=utf-8 再解释执行那个py文件试试,估计没问题 On Thu, 27 Sep 2007 00:00:25 +0800, @@ <askfor在gmail.com> wrote: >>>> str = '中秋快乐' >>>> print str.split('快') > ['\xd6\xd0\xc7\xef', '\xc0\xd6'] >>>> > 没报错。 > > 用str = u'中秋快乐' print str.split(u'快') > 看看吧 > > On 9/26/07, OnMyWay <onmyway.q在gmail.com> wrote: >> >> str='中秋快乐' >> print str.split('快') >> >> 但是报错,需要什么特别的语法吗? >> _______________________________________________ >> python-chinese >> Post: send python-chinese在lists.python.cn >> Subscribe: send subscribe to python-chinese-request在lists.python.cn >> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn >> Detail Info: http://python.cn/mailman/listinfo/python-chinese
2007年09月27日 星期四 09:41
utf8 下没有问题 不过还是建议不要用 str 这作为变量名 再,你这哪是 unicode ? 2007/9/26, OnMyWay <onmyway.q at gmail.com>: > str='中秋快乐' > print str.split('快') > > 但是报错,需要什么特别的语法吗?
2007年09月27日 星期四 14:04
# coding: utf-8
a = "google£¬baidu£¬ÎÒ"
b = a.split("£¬")
for i in b:
print i
ÉÏÃæÊǶԵÄ, ×¢ÒâÉÏÃæµÄ¶ººÅÊÇÖÐÎĶººÅ, ËùÒÔ˵ÓÃÖÐÎÄ·ÖûÓÐÎÊÌâ.ÕâÖÖ´¦Àí·Ç³£ÊʺÏÓÃÀ´´¦Àítag.
On 9/27/07, Jiahua Huang <jhuangjiahua在gmail.com> wrote:
>
> utf8 ÏÂûÓÐÎÊÌâ
> ²»¹ý»¹Êǽ¨Òé²»ÒªÓà str Õâ×÷Ϊ±äÁ¿Ãû
>
>
> ÔÙ£¬ÄãÕâÄÄÊÇ unicode £¿
>
>
> 2007/9/26, OnMyWay <onmyway.q在gmail.com>:
> > str='ÖÐÇï¿ìÀÖ'
> > print str.split('¿ì')
> >
> > µ«ÊDZ¨´í£¬ÐèÒªÊ²Ã´ÌØ±ðµÄÓï·¨Âð£¿
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
--
ÎÒ×ßµ½Ò»¸öİÉúµÄµØ·½, ¸æËß±ðÈË ÎÒҪȥÁ÷ÀË
Ŷ£¬ÎÒҪȥÁÆÉË¡¡
Gtalk: iexper(at)gmail.com
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070927/99d40c3e/attachment.html
2007年09月27日 星期四 14:19
tag 一般不是英文逗号分割么 在 07-9-27,大郎<iexper at gmail.com> 写道: > # coding: utf-8 > a = "google,baidu,我" > b = a.split(",") > for i in b: > print i > > 上面是对的, 注意上面的逗号是中文逗号, 所以说用中文分没有问题.这种处理非常适合用来处理tag. > >
Zeuux © 2025
京ICP备05028076号