I want to read from python stdin but also to have input options in my program. When I try to pass an option to my programm I get the error file not found and my arguments are discarded.
For parsing the arguments I use the following code:
parser=argparse.ArgumentParser(description='Training and Testing Framework')
parser.add_argument('--text', dest='text',
help='The text model',required=True)
parser.add_argument('--features', dest='features',
help='The features model',required=True)
parser.add_argument('--test', dest='testingset',
help='The testing set.',required=True)
parser.add_argument('--vectorizer', dest='vectorizer',
help='The vectorizer.',required=True)
args = vars(parser.parse_args())
For reading from the stdin I use the following code:
for line in sys.stdin.readlines():
print(preprocess(line,1))
Command Line
echo "dsfdsF" |python ensemble.py -h
/usr/local/lib/python2.7/dist-packages/pandas/io/excel.py:626: UserWarning: Installed openpyxl is not supported at this time. Use >=1.6.1 and <2.0.0.
.format(openpyxl_compat.start_ver, openpyxl_compat.stop_ver))
Traceback (most recent call last):
File "ensemble.py", line 38, in <module>
from preprocess import preprocess
File "/home/nikos/experiments/mentions/datasets/preprocess.py", line 7, in <module>
with open(sys.argv[1], 'rb') as csvfile:
IOError: [Errno 2] No such file or directory: '-h'