python核心编程-split分割

2016-01-14 08:10:21来源:CSDN作者:youhaibo1990人点击

string.split() ==>字符串分割
re.split() ==>正则表达式分割

#!/usr/bin/env python# -*- coding: UTF-8 -*-from os import popenimport ref = popen('dir', 'r')for eachLine in f.readlines():    print re.split('/s/s+|/t', eachLine.strip())f.close()

输出:

D:/Python27/test>re10.py
[‘/xc7/xfd/xb6/xaf/xc6/xf7 D /xd6/xd0/xb5/xc4/xbe/xed/xc3/xbb/xd3/xd0/xb1/xea/xc7/xa9/xa1/xa3’]
[‘/xbe/xed/xb5/xc4/xd0/xf2/xc1/xd0/xba/xc5/xca/xc7 7821-44F5’]
[”]
[‘D:/Python27/test /xb5/xc4/xc4/xbf/xc2/xbc’]
[”]
[‘2016/01/13’, ‘22:30’, ‘

’, ‘.’]
[‘2016/01/13’, ‘22:30’, ‘’, ‘..’]
[‘2015/09/12’, ‘11:12’, ‘1,097 atest.py’]
[‘2015/11/30’, ‘23:01’, ‘247 func.py’]
[‘2015/12/05’, ‘00:24’, ‘483 func10.py’]
[‘2015/12/05’, ‘21:05’, ‘702 func11.py’]
[‘2015/12/05’, ‘21:47’, ‘323 func12.py’]
[‘2015/12/05’, ‘22:10’, ‘645 func13.py’]
[‘2015/12/05’, ‘22:16’, ‘236 func14.py’]
[‘2015/12/05’, ‘22:27’, ‘345 func15.py’]
[‘2015/12/06’, ‘06:34’, ‘381 func16.py’]
[‘2015/12/06’, ‘06:39’, ‘259 func17.py’]
[‘2015/12/06’, ‘10:53’, ‘930 func18.py’]
[‘2015/12/06’, ‘11:22’, ‘407 func19.py’]
[‘2015/11/30’, ‘23:10’, ‘506 func2.py’]
[‘2015/12/07’, ‘21:38’, ‘239 func20.py’]
[‘2015/12/07’, ‘21:42’, ‘153 func21.py’]
[‘2015/12/07’, ‘21:55’, ‘255 func22.py’]
[‘2015/12/07’, ‘22:10’, ‘385 func23.py’]
[‘2015/12/07’, ‘22:15’, ‘165 func24.py’]
[‘2015/12/07’, ‘22:51’, ‘460 func25.py’]
[‘2015/11/30’, ‘23:49’, ‘1,104 func3.py’]
[‘2015/12/01’, ‘21:52’, ‘178 func4.py’]
[‘2015/12/01’, ‘23:50’, ‘328 func5.py’]
[‘2015/12/01’, ‘23:53’, ‘297 func6.py’]
[‘2015/12/04’, ‘00:10’, ‘653 func7.py’]
[‘2015/12/05’, ‘00:05’, ‘484 func8.py’]
[‘2015/12/05’, ‘00:13’, ‘642 func9.py’]
[‘2015/09/03’, ‘22:03’, ‘655 letter.py’]
[‘2015/12/15’, ‘22:54’, ‘350 mod1.py’]
[‘2015/12/20’, ‘15:21’, ‘327 object.py’]
[‘2015/12/20’, ‘15:52’, ‘798 object02.py’]
[‘2015/12/20’, ‘17:45’, ‘261 object03.py’]
[‘2015/12/20’, ‘17:49’, ‘203 object04.py’]
[‘2015/12/20’, ‘17:52’, ‘327 object05.py’]
[‘2015/12/20’, ‘18:02’, ‘311 object06.py’]
[‘2015/12/20’, ‘22:33’, ‘380 object07.py’]
[‘2015/12/20’, ‘22:35’, ‘796 object08.py’]
[‘2016/01/12’, ‘22:04’, ‘335 re01.py’]
[‘2016/01/12’, ‘22:10’, ‘135 re02.py’]
[‘2016/01/12’, ‘22:15’, ‘452 re03.py’]
[‘2016/01/12’, ‘22:28’, ‘758 re04.py’]
[‘2016/01/12’, ‘22:33’, ‘467 re05.py’]
[‘2016/01/12’, ‘23:21’, ‘1,862 re06.py’]
[‘2016/01/13’, ‘22:03’, ‘652 re07.py’]
[‘2016/01/13’, ‘22:20’, ‘193 re08.py’]
[‘2016/01/13’, ‘22:23’, ‘279 re09.py’]
[‘2016/01/13’, ‘22:39’, ‘196 re10.py’]
[‘2015/09/04’, ‘21:49’, ‘804 stack.py’]
[‘2015/09/02’, ‘22:10’, ‘345 test - /xb8/xb1/xb1/xbe.py’]
[‘2015/09/02’, ‘22:10’, ‘345 test.py’]
[‘2015/11/24’, ‘22:38’, ‘335 try-except.py’]
[‘2015/11/29’, ‘00:25’, ‘2,769 try-except02.py’]
[‘2015/09/04’, ‘00:13’, ‘414 unicode.py’]
[‘2015/09/12’, ‘10:42’, ‘1,044 userpw.py’]
[‘2016/01/13’, ‘22:34’, ‘349 whodata.txt’]
[‘54 /xb8/xf6/xce/xc4/xbc/xfe’, ‘28,046 /xd7/xd6/xbd/xda’]
[‘2 /xb8/xf6/xc4/xbf/xc2/xbc 76,208,840,704 /xbf/xc9/xd3/xc3/xd7/xd6/xbd/xda’]

D:/Python27/test>

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台