在Python 2.7解释器中,字符串拆分函数按预期工作:
>>> import string
>>> a = "a b c"
>>> string.split(a)
['a', 'b', 'c']但是,在Python 3.4.1解释器中,我得到一个错误:
>>> import string
>>> a = "a b c"
>>> string.split(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'split'你知道我错过了什么吗?
谢谢!
发布于 2014-09-09 16:02:50
您也可以在类str上调用它:
str.split("a b c")
['a', 'b', 'c']https://stackoverflow.com/questions/25739425
复制相似问题