a = string.split("Test Test2 Test3"," ")
Run Code Online (Sandbox Code Playgroud)
这会返回一个错误:
Message File Name Line Position
Traceback
<module> C:\pyWiz.py 43
AttributeError: 'module' object has no attribute 'split'
Run Code Online (Sandbox Code Playgroud)
是的,我导入了字符串模块.为什么会这样?
使用:
a = 'Test Test2 Test3'.split(' ')
Run Code Online (Sandbox Code Playgroud)
(即类型的split方法str).string.split在2.x中弃用并在3.x中消失.