with open(input('Enter file name: ')) as f: for line in f: if line.startswith('print'): print line[len('print')+1:]