2016-10-12 9 views

答えて

0

あなたはこのためにstartswith()を使用することができます。ここでは

numberOfTime = 0 
with open('httpd-access.txt') as f: 
    for line in f: 
     if line.startswith('81'): 
      numberOfTime += 1 

あなたが必要なものを達成するための機能:たくさんありがとう

def count_lines(httpd_file): 
    counter = 0 
    with open(httpd_file) as my_file: 
     for line in my_file: 
      if line.startswith('81'): 
       counter += 1 

    return counter 

if __name__ == '__main__': 
    print(count_lines('httpd-access.txt')) 
+0

!!それは仕事です! :) –

関連する問題