A vulnerability diagnostician who is not involved in development wrote a string search code for text

I've never done development, so I'm trying to make something for the time being.

First of all, programming to search for a character string in a text file with python. The reason I made it is because I often write sentences, so it was necessary to check prohibited characters.

Run from command line arguments

python01.png

If you hit the command prompt as above ...

pyhton02.png

Discover if the string "python" in pythontest.txt exists! Is displayed.

Contents of txt

pythontest.txt


Python pison paison puison poison peison poson

Below is the source.

stringParser.py


import sys
argvs = sys.argv
try:
	f = open(argvs[1],'r')
	for row in f:
		if row.find("Python") > -1:
			print("Discover! !!")
		else:
			print("Not found")
	f.close()
except:
	print("File not found")

It's like that. Command line arguments are basic for the time being, so I have to be able to use them!

Recommended Posts

A vulnerability diagnostician who is not involved in development wrote a string search code for text
Is there a good sample code for nosetests?