Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: object of type 'bool' has no len() in sys.argv length check [closed]

What is the reason for the error

TypeError: object of type 'bool' has no len()  

Should i import something in my python program? I am using len(sys.argv) in if condition to check for the number of command line arguments, which are float values(like 1.2 and 2.4, etc). Any thoughts? This is in python2.6. This is how i am running the program

python BeaconsAnalysis.py 2.0 3.0  

And some portion of my code where i am checking this is,

with open("luawrite", "r") as f:
    if(len(sys.argv == 2)):
            for line in f:
                    t1 = sys.argv[1]
                    t2 = sys.argv[2]
                    hashes = line.split()
                    t = hashes[0] 
                    ...........(goes on)
like image 921
Justin Carrey Avatar asked Jun 19 '13 00:06

Justin Carrey


1 Answers

You got the parens in the wrong place and need to account for the script name in argv[0]. if(len(sys.argv == 2)): should be if(len(sys.argv) == 3):

like image 152
tdelaney Avatar answered Oct 21 '22 09:10

tdelaney