为什么 python string split() 不分裂 [英] why is python string split() not splitting
问题描述
我有以下 python 代码.
I have the following python code.
class MainPage(BaseHandler):
def post(self, location_id):
reservations = self.request.get_all('reservations')
for r in reservations:
a=str(r)
logging.info("r: %s " % r)
logging.info("lenr: %s " % len(r))
logging.info("a: %s " % a)
logging.info("lena: %s " % len(a))
r.split(' ')
a.split(' ')
logging.info("split r: %s " % r)
logging.info("split a: %s " % a)
我得到以下日志打印输出.
I get the following log printout.
INFO 2012-09-02 17:58:51,605 views.py:98] r: court2 13 0 2012 9 2
INFO 2012-09-02 17:58:51,605 views.py:99] lenr: 20
INFO 2012-09-02 17:58:51,605 views.py:100] a: court2 13 0 2012 9 2
INFO 2012-09-02 17:58:51,606 views.py:101] lena: 20
INFO 2012-09-02 17:58:51,606 views.py:108] split r: court2 13 0 2012 9 2
INFO 2012-09-02 17:58:51,606 views.py:109] split a: court2 13 0 2012 9 2
如果我使用 split() 而不是 split(' '),我会得到相同的日志打印输出,顺便说一句.
I get the same log printout if instead of split(' ') I use split(), btw.
为什么 split 没有将结果拆分为一个包含 6 个条目的列表?我想问题是涉及到http请求,因为我在gae交互式控制台中的测试得到了预期的结果.
Why is split not splitting the result into a list with 6 entries? I suppose the problem is that http request is involved, because my tests in the gae interactive console get the expected result.
推荐答案
split
不修改字符串.它返回拆分件的列表.如果要使用该列表,则需要将其分配给某些内容,例如 r = r.split(' ')
.
split
does not modify the string. It returns a list of the split pieces. If you want to use that list, you need to assign it to something with, e.g., r = r.split(' ')
.
这篇关于为什么 python string split() 不分裂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!