Created
October 25, 2013 13:56
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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