My code to access command line argument:
length = len(sys.argv)
print length
str = sys.arvg[0]
print str
gives output :
triongle@triongle.com [~/download/DataInsertionScript]# python IngestDataToMongo.py python_sucks
2
Traceback (most recent call last):
File "IngestDataToMongo.py", line 83, in <module>
str = sys.arvg[0]
AttributeError: 'module' object has no attribute 'arvg'
So, first time len(sys.argv) works but strangely next time gives error on sys.argv[0]. So why is it?
You have written
sys.arvg[0]instead ofsys.argv[0]. Also be sure toimportthesysmodule, because argv by default belongs to that namespace.