Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

string.split error? python

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

This returns an error:

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

Yes, I imported the string module. Why is this happening?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use:

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

(i.e. split method of str type). string.split is deprecated in 2.x and gone in 3.x.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...