None, False, True

Discussion in 'Python' started by M-a-S, Sep 16, 2003.

  1. M-a-S

    M-a-S Guest

    Can anybody explain this:

    Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    >>> None = 3

    <stdin>:1: SyntaxWarning: assignment to None
    >>> False = 4
    >>> True = 5
    >>>
    >>> None, False, True

    (3, 4, 5)
    >>>
     
    M-a-S, Sep 16, 2003
    #1
    1. Advertising

  2. M-a-S <> spake thusly:
    > Can anybody explain this:
    >
    > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on
    > win32 Type "help", "copyright", "credits" or "license" for more
    > information.
    >>>>
    >>>> None = 3

    > <stdin>:1: SyntaxWarning: assignment to None
    >>>> False = 4
    >>>> True = 5
    >>>>
    >>>> None, False, True

    > (3, 4, 5)


    http://www.ibiblio.org/obp/thinkCSpy/chap05.htm

    In section 5.9 (Glossary) near the bottom of the link above I found this
    entry for None...

    None
    A special Python value returned by functions that have no
    return statement, or a return statement without an argument.

    Maybe that has something to do with it.

    --
    Remove BLINDERS to email me.
    Audio Bible Online:
    http://www.audio-bible.com/
     
    Indigo Moon Man, Sep 16, 2003
    #2
    1. Advertising

  3. M-a-S

    anton muhin Guest

    Indigo Moon Man wrote:

    > M-a-S <> spake thusly:
    >
    >>Can anybody explain this:
    >>
    >>Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on
    >>win32 Type "help", "copyright", "credits" or "license" for more
    >>information.
    >>
    >>>>>None = 3

    >>
    >><stdin>:1: SyntaxWarning: assignment to None
    >>
    >>>>>False = 4
    >>>>>True = 5
    >>>>>
    >>>>>None, False, True

    >>
    >>(3, 4, 5)

    >
    >
    > http://www.ibiblio.org/obp/thinkCSpy/chap05.htm
    >
    > In section 5.9 (Glossary) near the bottom of the link above I found this
    > entry for None...
    >
    > None
    > A special Python value returned by functions that have no
    > return statement, or a return statement without an argument.
    >
    > Maybe that has something to do with it.
    >


    Defenitely. If I remember it right, None is going to be promoted into
    keywords soon. Therefore the warning.

    hth,
    anton.
     
    anton muhin, Sep 16, 2003
    #3
  4. M-a-S

    John J. Lee Guest

    "M-a-S" <> writes:

    > Can anybody explain this:
    >
    > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
    > Type "help", "copyright", "credits" or "license" for more information
    > >>> None = 3

    > <stdin>:1: SyntaxWarning: assignment to None
    > >>> False = 4
    > >>> True = 5
    > >>>
    > >>> None, False, True

    > (3, 4, 5)


    I believe there have been discussions about preventing the clobbering
    of builtins recently, so it may happen in the future (2.4?).

    Dunno why None and not True / False causes a warning, but you can turn
    warnings into errors using the warnings framework, I think.


    John
     
    John J. Lee, Sep 16, 2003
    #4
  5. M-a-S

    Max M Guest

    M-a-S wrote:

    > Can anybody explain this:
    >
    > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
    > Type "help", "copyright", "credits" or "license" for more information.
    >
    >>>>None = 3

    >
    > <stdin>:1: SyntaxWarning: assignment to None
    >
    >>>>False = 4
    >>>>True = 5
    >>>>
    >>>>None, False, True

    >
    > (3, 4, 5)


    Yes. You assign new values to the objects None, False and True. You then
    print out those values in a tuple.

    What's not to understand?

    But for others reading your programme you might be better of to keep
    them their normal values.


    regards Max M
     
    Max M, Sep 16, 2003
    #5
  6. John> Dunno why None and not True / False causes a warning, but you can
    John> turn warnings into errors using the warnings framework, I think.

    Too much Python code which needs to run on 2.2 or earlier legitimately
    defines True and False something like so:

    try:
    True
    except NameError:
    True = (1 == 1)
    False = not True

    All that valid code would raise SyntaxWarning if it was enabled for True and
    False. Note that SyntaxWarning is raised at compilation time, not runtime,
    so the compiler doesn't know a priori whether the except clause will
    execute.

    Skip
     
    Skip Montanaro, Sep 16, 2003
    #6
  7. [John J Lee]
    > Dunno why None and not True / False causes a warning


    Because there is a lot of existing code that legitimately made
    assignments to True and False.

    > but you can turn
    > warnings into errors using the warnings framework, I think.


    Right!


    Raymond
     
    Raymond Hettinger, Sep 16, 2003
    #7
  8. M-a-S

    M-a-S Guest

    "anton muhin" <> wrote in message news:bk7mkg$4s$...

    > Defenitely. If I remember it right, None is going to be promoted into
    > keywords soon. Therefore the warning.
    >
    > hth,
    > anton.
    >


    Will it be lower-case (together with false and true) like all other keywords or is it just a start of mess?

    M-a-S
     
    M-a-S, Sep 16, 2003
    #8
  9. M-a-S

    M-a-S Guest

    "Max M" <> wrote in message news:3f675ecd$0$97184$...
    >
    > Yes. You assign new values to the objects None, False and True. You then
    > print out those values in a tuple.
    >
    > What's not to understand?
    >
    > But for others reading your programme you might be better of to keep
    > them their normal values.


    Which are ...?

    I mean what are None, False and True? Are they just identifiers? Are they
    variables defined in __builtins__? Are they literals? Are they language "bricks"
    like "for" and "1"?
     
    M-a-S, Sep 16, 2003
    #9
  10. "M-a-S" <> writes:

    > Will it be lower-case (together with false and true) like all other
    > keywords or is it just a start of mess?


    It is a start of mess.

    Actually, None will be the first in a new category of token, the
    "reserved identifiers". The exact lexical properties of such tokens
    still need to be determined, and it might be that None is only the
    second in its category, following "as".

    Martin
     
    Martin v. =?iso-8859-15?q?L=F6wis?=, Sep 16, 2003
    #10

  11. >> If I remember it right, None is going to be promoted into keywords
    >> soon. Therefore the warning.


    M-a-S> Will it be lower-case (together with false and true) like all
    M-a-S> other keywords or is it just a start of mess?

    Python is a case-sensitive language. Variables named "none" and "None" are
    different. It's unlikely that Python's case-sensitive properties will
    change, so the SyntaxWarning will only be raised for "None".

    Skip
     
    Skip Montanaro, Sep 16, 2003
    #11
  12. M-a-S

    John Roth Guest

    "M-a-S" <> wrote in message
    news:5MJ9b.13244$...
    >
    > "Max M" <> wrote in message

    news:3f675ecd$0$97184$...
    > >
    > > Yes. You assign new values to the objects None, False and True. You then
    > > print out those values in a tuple.
    > >
    > > What's not to understand?
    > >
    > > But for others reading your programme you might be better of to keep
    > > them their normal values.

    >
    > Which are ...?
    >
    > I mean what are None, False and True? Are they just identifiers? Are they
    > variables defined in __builtins__? Are they literals? Are they language

    "bricks"
    > like "for" and "1"?


    As of 2.3, they are unique objects in the builtins name space. As such,
    they can be shadowed, which is what causes the confusion.

    John Roth
    >
    >
     
    John Roth, Sep 16, 2003
    #12
  13. M-a-S

    M-a-S Guest

    "Skip Montanaro" <> wrote in message news:...
    >
    > >> If I remember it right, None is going to be promoted into keywords
    > >> soon. Therefore the warning.

    >
    > M-a-S> Will it be lower-case (together with false and true) like all
    > M-a-S> other keywords or is it just a start of mess?
    >
    > Python is a case-sensitive language. Variables named "none" and "None" are
    > different. It's unlikely that Python's case-sensitive properties will
    > change, so the SyntaxWarning will only be raised for "None".
    >
    > Skip


    That's why I feel that none, true and false must be literals and keywords (not variables).

    BTW this won't prevent True and False from staying in the language (till 3.0 :)
    and behaving exactly as they do now:

    >>> True = False; False = not True
    >>>
    >>> False

    True
    >>> True

    False

    Only the output will be

    >>> False

    true
    >>> True

    false


    M-a-S
     
    M-a-S, Sep 16, 2003
    #13
  14. M-a-S

    Terry Reedy Guest

    "M-a-S" <> wrote in message
    news:5MJ9b.13244$...
    > I mean what are None, False and True? Are they just identifiers? Are

    they
    > variables defined in __builtins__? Are they literals? Are they

    language "bricks"
    > like "for" and "1"?


    You are trying too hard ;-)

    They are currently names in the builtin namespace bound to PyObjects,
    just like all other builtin names. That means that they can be
    shadowed by global or local names, just like all other builtin names.

    There is a proposal to change the status of None, and possibly, True
    and False, sometime in the future. Hence the warning (also issued
    because reassignment of None is likely a mistake).

    Terry J. Reedy
     
    Terry Reedy, Sep 17, 2003
    #14
  15. M-a-S

    Gregor Lingl Guest

    M-a-S schrieb:

    > Can anybody explain this:
    >
    > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
    > Type "help", "copyright", "credits" or "license" for more information.
    >
    >>>>None = 3

    >
    > <stdin>:1: SyntaxWarning: assignment to None
    >


    Interestingly this doesn't occur in IDLE:

    Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license()" for more information.
    ....
    IDLE 1.0
    >>> None = 3

    SyntaxError: assignment to None (<pyshell#0>, line 1)
    >>> print None

    None

    In a recent posting to this list I asked how to write-protect
    names. This seems to be done here with the Name None.
    But again: how is it done?

    ----
    On the other side the existence and knowledge of the None-object
    doesn't disappear completely in the plain Python interpreter:

    >>> None = 3

    <stdin>:1: SyntaxWarning: assignment to None
    >>> None

    3
    >>> def f():

    .... pass
    ....
    >>> print f()

    None

    But:

    >>> def g():

    .... return None
    ....
    >>> g()

    3

    So you can use f to restore the value of None
    (if you happened to forget to save it):

    >>> None = f()

    <stdin>:1: SyntaxWarning: assignment to None
    >>> None
    >>> print None

    None
     
    Gregor Lingl, Sep 17, 2003
    #15
  16. M-a-S

    Gregor Lingl Guest

    Gregor Lingl schrieb:

    .....

    >
    > Interestingly this doesn't occur in IDLE:
    >
    > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on
    > win32
    > Type "copyright", "credits" or "license()" for more information.
    > ...
    > IDLE 1.0
    > >>> None = 3

    > SyntaxError: assignment to None (<pyshell#0>, line 1)
    > >>> print None

    > None


    remark:

    If you run the script:

    None = 3
    print None


    within IDLE, it does NOT issue a syntax error,
    but prints 3 (i. e. it works like the plain python interpreter)

    Gregor
     
    Gregor Lingl, Sep 17, 2003
    #16
  17. M-a-S

    Duncan Booth Guest

    Gregor Lingl <> wrote in news::

    > On the other side the existence and knowledge of the None-object
    > doesn't disappear completely in the plain Python interpreter:
    >
    > >>> None = 3

    ><stdin>:1: SyntaxWarning: assignment to None
    > >>> None

    > 3
    > >>> def f():

    > ... pass
    > ...
    > >>> print f()

    > None
    >
    > But:
    >
    > >>> def g():

    > ... return None
    > ...
    > >>> g()

    > 3
    >
    > So you can use f to restore the value of None
    > (if you happened to forget to save it):
    >
    > >>> None = f()

    ><stdin>:1: SyntaxWarning: assignment to None
    > >>> None
    > >>> print None

    > None


    Or, much more easily, you could simply use 'del None' to remove the global
    None you defined leaving the builtin None visible again.

    --
    Duncan Booth
    int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
    "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
     
    Duncan Booth, Sep 18, 2003
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. André
    Replies:
    3
    Views:
    1,596
  2. bdb112
    Replies:
    45
    Views:
    1,348
    jazbees
    Apr 29, 2009
  3. length power
    Replies:
    2
    Views:
    80
    Rustom Mody
    Apr 10, 2014
  4. Skip Montanaro
    Replies:
    0
    Views:
    62
    Skip Montanaro
    Apr 10, 2014
  5. Johannes Schneider

    Re: why i have the output of [None, None, None]

    Johannes Schneider, Apr 10, 2014, in forum: Python
    Replies:
    0
    Views:
    53
    Johannes Schneider
    Apr 10, 2014
Loading...

Share This Page