python split实现awk -F分割字符串实例
>>> 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']
标签: python
发表评论: