def grep ( pattern , filename ) : try : # for line in file # if line matches pattern: #    return line return next ( ( L for L in open ( filename ) if L . find ( pattern ) >= 0 ) ) except StopIteration : return ''
hoe to get a matching pattern in a file in python
Very simple grep that returns the first matching line in a file . String matching only does not do REs as currently implemented .
def grep(pattern, filename):
    """Very simple grep that returns the first matching line in a file.
    String matching only, does not do REs as currently implemented.
    """
    try:
        # for line in file
        # if line matches pattern:
        #    return line
        return next((L for L in open(filename) if L.find(pattern) >= 0))
    except StopIteration:
        return ''