如果我正确理解您的意见,然后拆分应该采取的措施:
if "$Revision:" in line:
print(line.split("$Revision: ")[1].split()[0])
1.14
In [6]: line ="""
...: -- CVS Header: $Source: /CVS/oracle11i/database/erp/apps/pkgspec/wwt_prime_pkg.p
...: ls,v $, $Revision: 1.14 $, $Author: $, $Date: 2014/09/23 21:41:15 $
...: """
In [7]: line.split("$Revision: ") # split the line at $Revision:
Out[7]:
['\n-- CVS Header: $Source: /CVS/oracle11i/database/erp/apps/pkgspec/wwt_prime_pkg.p\nls,v $, ',
'1.14 $, $Author: $, $Date: 2014/09/23 21:41:15 $\n']
# we use indexing to get the first element after $Revision: in the string
In [8]: line.split("$Revision: ")[1]
# which becomes the substring below
Out[8]: '1.14 $, $Author: $, $Date: 2014/09/23 21:41:15 $\n'
# if we call split again we split that substring on whitespace into individual strings
In [10]: '1.14 $, $Author: $, $Date: 2014/09/23 21:41:15 $\n'.split()
Out[10]: ['1.14', '$,', '$Author:', '$,', '$Date:', '2014/09/23', '21:41:15', '$']
# using indexing again we extract the first element which is the revision number
In [11]: '1.14 $, $Author: $, $Date: 2014/09/23 21:41:15 $\n'.split()[0]
Out[11]: '1.14'
$Date相同:
date = line.split("$Date: ")[1].split()[0]
或者,如果您只想检查字符串中的子字符串,请使用in:
if "$Revision: 1.14" in line:
print line