i have a python script name as neural_net.py . It classify the mnist dataset. What i want to do is to run it via command line by taking input from user. The following snippet is taking input from user
file=input()
from PIL import Image
im = Image.open(file).convert('L')
imr=np.array(im).T
single_test = imr.reshape(1,400)
plt.figure(figsize=(5,5))
plt.imshow(imr)
print("value is",nn.predict(single_test))
in command prompt i have to run it as following
python neural_net.py
execute the above line and then give the input
pic_0.png
and it return me the output. What i want is to do the both of above things as a single command such as
python neural_net.py pic_0.png
file = sys.argv[1]to get it. If you run with more arguments then you havesys.argv[2], etc. If you need more complex soluton likescript.py --input pic_0.png --output image.pngthen see module argparse