Skip to content

Instantly share code, notes, and snippets.

@sscarduzio
Created October 25, 2013 13:56
Show Gist options
  • Save sscarduzio/7155099 to your computer and use it in GitHub Desktop.
Save sscarduzio/7155099 to your computer and use it in GitHub Desktop.
grepFromString with caseSensitive=False never executes the body of the for beyond the "if caseSensitive" statement (line 12)
def grepFromFile(filename, string):
content = run('cat' + filename, capture=True)
return grep(content, string)
def grepFromString(haystack, needle, caseSensitive):
result = None
if(caseSensitive):
needle = needle.lower()
s = StringIO.StringIO(haystack)
for line in s:
if caseSensitive:
line = line.lower()
if needle in line:
result = result + [line, ]
return result
def main():
res = grepFromString("""
hello
Kill
Me
Please
""", "me", False)
print res
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment