-
Notifications
You must be signed in to change notification settings - Fork 0
/
grep.py
44 lines (30 loc) · 799 Bytes
/
grep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import re;
class grep():
"""This is a qucik version of 'grep a list' I wrote for testing"""
def __init__(self,*args):
#print 'Foo'
str = None
target = None;
matches = [];
if(len(args) == 0):
print 'No items! to search'
if(len(args) >= 1):
str = args[0];
if(len(args) >= 2):
target = args[1];
#try to search for matches in the target
if (str is not None) and (target is not None):
reg = re.compile(re.escape(str),re.I)
for item in target:
if reg and (reg.search( item) is not None) :
matches.append( item )
if (matches is not None):
print matches
def clear(size=50):
"""quick function hack to clear the screen"""
for i in range(0,size): print "";
def main():
print 'main'
#g = grep()
if __name__ == '__main__':
main();