True

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Bennetts

    #16
    Re: True

    On Sun, Oct 19, 2003 at 08:17:15AM -0700, David Eppstein wrote:[color=blue]
    > In article <3f929cf0$1_1@t hemost.net>,
    > "Paul Watson" <pwatson@redlin ec.com> wrote:
    >[color=green]
    > > Then, what is the best way to write boolean operations for Python 2.1 so
    > > that it will be as 2.3+ ready as possible?[/color]
    >
    > I've been including the following at the start of some of my code:
    >
    > if 'True' not in globals():
    > globals()['True'] = not None
    > globals()['False'] = not True[/color]

    Why not simply:

    try:
    True
    except NameError:
    True = (1 == 1) # or not None, if you prefer
    False = not True

    Or were you trying to change the __builtins__ by using globals()?

    -Andrew.


    Comment

    • Duncan Booth

      #17
      Re: True

      David Eppstein <eppstein@ics.u ci.edu> wrote in news:eppstein-
      D286CF.08171519 102003@news.ser vice.uci.edu:
      [color=blue][color=green]
      >> Then, what is the best way to write boolean operations for Python 2.1 so
      >> that it will be as 2.3+ ready as possible?[/color]
      >
      > I've been including the following at the start of some of my code:
      >
      > if 'True' not in globals():
      > globals()['True'] = not None
      > globals()['False'] = not True
      >
      > My hope is that setting up True and False in this convoluted way will
      > allow it to continue to work in some future version where assignment to
      > builtins is disallowed.[/color]

      Since True will never be in globals unless you assign it there, you might
      as well just drop the if statement altogether. Also I fail to see what
      benefit you gain from the contorted assignment into the globals dictionary.
      Why not just write:

      True = not None
      False = not True

      It has the same effect overall.

      If you want to avoid hiding the builtin True and False, then use try..catch
      to detect them.

      --
      Duncan Booth duncan@rcp.co.u k
      int month(char *p){return(1248 64/((p[0]+p[1]-p[2]&0x1f)+1)%12 )["\5\x8\3"
      "\6\7\xb\1\x9\x a\2\0\4"];} // Who said my code was obscure?

      Comment

      • Peter Otten

        #18
        Re: True

        Andrew Bennetts wrote:
        [color=blue]
        > On Sun, Oct 19, 2003 at 08:17:15AM -0700, David Eppstein wrote:[color=green]
        >> In article <3f929cf0$1_1@t hemost.net>,
        >> "Paul Watson" <pwatson@redlin ec.com> wrote:
        >>[color=darkred]
        >> > Then, what is the best way to write boolean operations for Python 2.1
        >> > so that it will be as 2.3+ ready as possible?[/color]
        >>
        >> I've been including the following at the start of some of my code:
        >>
        >> if 'True' not in globals():
        >> globals()['True'] = not None
        >> globals()['False'] = not True[/color]
        >
        > Why not simply:
        >
        > try:
        > True
        > except NameError:
        > True = (1 == 1) # or not None, if you prefer
        > False = not True
        >
        > Or were you trying to change the __builtins__ by using globals()?
        >
        > -Andrew.[/color]

        I suppose David tries to avoid a syntax error raised by the assignment

        True = somethingElse

        in a future version of Python. Therefore he has "hidden" the builtins to be
        assigned from the compiler by turning them into strings.

        Peter



        Comment

        • David Eppstein

          #19
          Re: True

          In article <bn0cf2$liu$01$ 1@news.t-online.com>,
          Peter Otten <__peter__@web. de> wrote:
          [color=blue]
          > I suppose David tries to avoid a syntax error raised by the assignment
          >
          > True = somethingElse
          >
          > in a future version of Python. Therefore he has "hidden" the builtins to be
          > assigned from the compiler by turning them into strings.[/color]

          Yes, exactly.

          --
          David Eppstein http://www.ics.uci.edu/~eppstein/
          Univ. of California, Irvine, School of Information & Computer Science

          Comment

          Working...