Interesting list Validity (True/False)

nufuhsus at gmail.com nufuhsus at gmail.com
Fri May 11 15:28:24 EDT 2007


Hello all,

First let me appologise if this has been answered but I could not find
an acurate answer to this interesting problem.

If the following is true:
    C:\Python25\rg.py>python
    Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32
bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more
information.
    >>> [] == []
    True
    >>> ['-o'] == []
    False
    >>> ['-o'] == False
    False
    >>>

Then why do I get the following results:
    C:\Python25\rg.py>help.py -o
    print arg ['-o']
    type(arg): <type 'list'>
    arg is True? False
        help.py version 1.0 Copyright RDEG (c) 2007
        ['-o'] is an unrecognized option.
        Progam Exit (0)

<python>
    import sys

    _ver_ = 1.00

    if '-h' in sys.argv or '--help' in sys.argv:
        print
        print "    help.py Version", _ver_, "Copyright RDEG (c) 2007"
        print '''

        Options : -h, --help -- display this message
            Progam Exit (0)'''
        sys.exit(0)
    else:
        arg = sys.argv[1:]
        print 'print arg', arg
        print 'type(arg):', type(arg)
        print 'arg is True?', arg == True
        print "    help.py version", _ver_, "Copyright RDEG (c) 2007"
        print "    ", arg, "is an unrecognized option."
        print "    Progam Exit (0)"
        sys.exit(0)
</python>




More information about the Python-list mailing list