jython: True and False boolean literals?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davidmichaelkarr@gmail.com

    #1

    jython: True and False boolean literals?

    Aren't there boolean literals for "True" and "False" in Python
    (jython)? I can't get "true", "True", "false", or "False" to work. I
    ended up having to use "(1==1)" and "(1==0)".

  • keirr

    #2
    Re: jython: True and False boolean literals?

    davidmichaelkar r@gmail.com wrote:[color=blue]
    > Aren't there boolean literals for "True" and "False" in Python[/color]
    [color=blue][color=green][color=darkred]
    >>> True != False[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> type(True)[/color][/color][/color]
    <type 'bool'>

    works for most people :-)

    All the best,

    Keir

    Comment

    • keirr

      #3
      Re: jython: True and False boolean literals?


      keirr wrote:[color=blue]
      > davidmichaelkar r@gmail.com wrote:[color=green]
      > > Aren't there boolean literals for "True" and "False" in Python[/color]
      >[color=green][color=darkred]
      > >>> True != False[/color][/color]
      > True[color=green][color=darkred]
      > >>> type(True)[/color][/color]
      > <type 'bool'>
      >
      > works for most people :-)
      >[/color]
      Ahem, who use python. For jython this looks like[color=blue][color=green][color=darkred]
      >>> True != False[/color][/color][/color]
      1[color=blue][color=green][color=darkred]
      >>> type(True)[/color][/color][/color]
      <type 'int'>

      Keir.

      Comment

      • Kent Johnson

        #4
        Re: jython: True and False boolean literals?

        davidmichaelkar r@gmail.com wrote:[color=blue]
        > Aren't there boolean literals for "True" and "False" in Python
        > (jython)? I can't get "true", "True", "false", or "False" to work. I
        > ended up having to use "(1==1)" and "(1==0)".[/color]

        No, there are not. Jython implements Python 2.1 which did not have boolean literals. You
        can just use 1 and 0.

        Kent

        Comment

        • keirr

          #5
          Re: jython: True and False boolean literals?

          Kent Johnson wrote:[color=blue]
          > davidmichaelkar r@gmail.com wrote:[color=green]
          > > Aren't there boolean literals for "True" and "False" in Python
          > > (jython)? I can't get "true", "True", "false", or "False" to work. I
          > > ended up having to use "(1==1)" and "(1==0)".[/color]
          >
          > No, there are not. Jython implements Python 2.1 which did not have boolean literals. You
          > can just use 1 and 0.
          >[/color]
          The latest jython is 2.2a1 (which does have True and False as ints)

          You could declare your own True and False like this:
          class Boolean:
          __init__(self, value):
          self.__value = value
          __repr__(self):
          return self.__value != 0
          __int__(self):
          return int(self.__valu e)
          and so on.

          then, True = Boolean(1)
          and False = Boolean(0)

          Cheers,
          Keir

          Comment

          • Bengt Richter

            #6
            Re: jython: True and False boolean literals?

            On 22 Dec 2005 10:51:22 -0800, davidmichaelkar r@gmail.com wrote:
            [color=blue]
            >Aren't there boolean literals for "True" and "False" in Python
            >(jython)? I can't get "true", "True", "false", or "False" to work. I
            >ended up having to use "(1==1)" and "(1==0)".
            >[/color]
            You may want to upgrade to a newer version.

            Regards,
            Bengt Richter

            Comment

            Working...