松哥的笔记
python split实现awk -F分割字符串实例
2013-9-27 lqy
>>> ts = "root     16788  0.0  0.1   4944   892 pts/1    R+   11:57   0:00 ps xua"
>>> ts
'root 16788 0.0 0.1 4944 892 pts/1 R+ 11:57 0:00 ps xua'
>>> ts.split()
['root', '16788', '0.0', '0.1', '4944', '892', 'pts/1', 'R+', '11:57', '0:00', 'ps', 'xua']
>>> ts.split(" ",1)
['root', ' 16788 0.0 0.1 4944 892 pts/1 R+ 11:57 0:00 ps xua']
>>> tf = ts.split(" ",1)
>>> tf[0:1]
['root']
>>> tf[0:]
['root', ' 16788 0.0 0.1 4944 892 pts/1 R+ 11:57 0:00 ps xua']
>>> tf[:1]
['root']
>>> tf[1:]
[' 16788 0.0 0.1 4944 892 pts/1 R+ 11:57 0:00 ps xua']


发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容