Skip to main content
 首页 » 编程设计

python之string.split 错误 Python

2025年05月04日10kenshinobiy

a = string.split("Test Test2 Test3"," ") 

这会返回一个错误:

Message File Name   Line    Position     
Traceback                
    <module>    C:\pyWiz.py 43       
AttributeError: 'module' object has no attribute 'split'                 

是的,我导入了字符串模块。 为什么会这样?

请您参考如下方法:

使用:

a = 'Test Test2 Test3'.split(' ') 

(即 str 类型的 split 方法)。 string.split 在 2.x 中被弃用并在 3.x 中消失。