search for similar words. contains.
This isn't fully tested, but it looks promising.
This is a parser that will search through a file for words containing a sequence of stuff you search for, like if I want to know how many times I use a variable 'carrots' or anything containing that word in a file. Maybe you want to know how many times you repeat yourself, or just search for similarities... I'm sure it can be better, and it's probably highly unpythonic, but work in progress!
Distraction for the day!
update: fixed the copy paste. Blogger doesn't like to paste visual studio code correctly.
import argparse
import re
parser = argparse.ArgumentParser()
parser.add_argument('file', help="file to search through")
parser.add_argument('similate', type=str, help='character similate to find in fuzz.')
args = parser.parse_args()
def main(args):
words = []
if args.file:
similar_stuff= []
with open(args.file) as f:
for line in f:
count = 0
# first clean removes all non alpha numerics
clean = re.sub("[^\w]", " ", line).split()
index = 0
for items in clean:
current = clean[index]
#print(current)
similate = args.similate
index += 1
if similate in current:
similar_stuff.append(current)
print(f" simular = {similar_stuff}")
if __name__ == "__main__":
main(args)
This is a parser that will search through a file for words containing a sequence of stuff you search for, like if I want to know how many times I use a variable 'carrots' or anything containing that word in a file. Maybe you want to know how many times you repeat yourself, or just search for similarities... I'm sure it can be better, and it's probably highly unpythonic, but work in progress!
Distraction for the day!
update: fixed the copy paste. Blogger doesn't like to paste visual studio code correctly.
import argparse
import re
parser = argparse.ArgumentParser()
parser.add_argument('file', help="file to search through")
parser.add_argument('similate', type=str, help='character similate to find in fuzz.')
args = parser.parse_args()
def main(args):
words = []
if args.file:
similar_stuff= []
with open(args.file) as f:
for line in f:
count = 0
# first clean removes all non alpha numerics
clean = re.sub("[^\w]", " ", line).split()
index = 0
for items in clean:
current = clean[index]
#print(current)
similate = args.similate
index += 1
if similate in current:
similar_stuff.append(current)
print(f" simular = {similar_stuff}")
if __name__ == "__main__":
main(args)
Comments
Post a Comment