michael wrote: > EXCLUDE='' #Lines beginning with this should not be printed. > > def get_line() : > buf = f.readline() > if (buf and buf[0] == EXCLUDE): > return 0 > else: > return buf If 'EXCLUDE' is '', buf[0] will never == EXCLUDE. Imagine that you want to exclude lines beginning with '#'. I think you could then write your whole program as follows: FILENAME = '/etc/hosts.deny' OUTPUT = 'hosts.deny.test' orig = open(FILENAME) lines = orig.readlines() orig.close() def skip(line): return line[:1] == '#' filtered = open(OUTPUT,'w') for linenum in range(len(lines)): line = lines[linenum] if skip(line): continue if line in lines[:linenum]: # duplicate continue filtered.write(line) filtered.close() -Steve -- Steve Purcell, Pythangelist Get testing at http://pyunit.sourceforge.net/ Any opinions expressed herein are my own and not necessarily those of Yahoo
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4