-1

を含むファイルがあります

"1111 1111 1111 // google 
1111 1111 1111 // google talk browser 
1111 1111 1111 // google talks 
1111 1111 1111 // google talk" 

「//グーグルトーク」関連の行だけを印刷したい(4行目のみ)

このようにこれが機能しないようにしてみました...

with open('file.txt', 'r') as handle:
    for index, line in enumerate(handle, 1):
        if line.strip() == 'talk':
            print 'Match found on line', index
4

1 に答える 1

3
with open('file.txt', 'r') as handle:
    for index, line in enumerate(handle, 1):
        if line.rstrip().endswith("// google talk") # or .endswith("talk")
            print 'Match found on line', index
于 2012-10-04T06:59:51.167 に答える