8

in Python, i'd like to check to make sure a command line argument is of type bool before I use it in a conditional statement. this: isinstance(sys.argv[2], bool) is coming back false. What's the right way to do this?

Ramy
  • 20,541
  • 41
  • 103
  • 153
  • 5
    whoever downvoted this clearly has not understood what this site is about: you don't vote on the content, you vote on the form. this is actually quite well written as beginner questions go. –  Apr 19 '11 at 15:18

2 Answers2

7

All command line arguments are strings. Please refine what you want.

If you want to check for the argument true, check if sys.argv[2] equals 'true'.

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
orlp
  • 112,504
  • 36
  • 218
  • 315
6

As nightcracker said, command line arguments are strings.
You can use sys.argv[2] in ('True', 'False').

wong2
  • 34,358
  • 48
  • 134
  • 179