Last active
August 1, 2021 18:59
-
-
Save ntlk/7162075 to your computer and use it in GitHub Desktop.
grep made bad in python
This file contains hidden or 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
import sys | |
import re | |
pattern = re.compile(sys.argv[1]) | |
last = int(len(sys.argv)) - 1 | |
reverse = True if sys.argv[last] == '-v' else False | |
lines = sys.stdin.readlines() | |
for line in lines: | |
if bool(pattern.search(line)) != reverse: | |
sys.stdout.write(line) |
You can just do:
reverse = sys.argv[last] == '-v'
Instead of the if/else.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
w..why?
(also, why not ack?)