How can it be that len ​​(sys.argv) <= 0?

The following error occurred in my code, and I do not understand how this case can occur:

if(len(sys.argv) > 0):
    doSomething()
else:
    raise AttributeError("Could not parse script name")

The above code is in the python class that I import and use in some script. I use the same class with the same call in other scripts and it works great everywhere. FYI, my OS is ubuntu.

How is it possible that len ​​(sys.argv) is <= 0?

+4
source share
1 answer

Ok, so we found the answer; @nneonneo gave the correct hint, at some point, actually argv was changed:

args = sys.argv
del args[0]

, - , sys.argv [0]. :

args = sys.argv[1:]

!

+1

All Articles