#! /usr/bin/env python # -*- coding: utf8 -*- import sys word = sys.argv[1] if len(sys.argv) > 1 else "file" with open("slides.tex", 'r') as myfile: # total_nb = sum([ line.count(word) for line in myfile ]) total_nb = sum( line.count(word) for line in myfile ) print "The word '{}' is present {} times in my file {}.".format(word, total_nb, myfile.name)