469,286 Members | 2,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

None, False, True

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)


Jul 18 '05 #1
16 6657
M-a-S <NO*****@hotmail.com> 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/
Jul 18 '05 #2
Indigo Moon Man wrote:
M-a-S <NO*****@hotmail.com> 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.

Jul 18 '05 #3
"M-a-S" <NO*****@hotmail.com> 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
Jul 18 '05 #4
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

Jul 18 '05 #5
[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
Jul 18 '05 #6

"anton muhin" <an********************************@rambler.ru> wrote in message news:bk*********@news.peterlink.ru...
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
Jul 18 '05 #7

"Max M" <ma**@mxm.dk> wrote in message news:3f***********************@dread12.news.tele.d k...

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"?
Jul 18 '05 #8

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
Jul 18 '05 #9
"M-a-S" <NO*****@hotmail.com> 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
Jul 18 '05 #10

"M-a-S" <NO*****@hotmail.com> wrote in message
news:5M******************@twister.southeast.rr.com ...

"Max M" <ma**@mxm.dk> wrote in message news:3f***********************@dread12.news.tele.d k...

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

Jul 18 '05 #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
Jul 18 '05 #12

"Skip Montanaro" <sk**@pobox.com> wrote in message news:ma**********************************@python.o rg...
>> 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
Jul 18 '05 #13

"M-a-S" <NO*****@hotmail.com> wrote in message
news:5M******************@twister.southeast.rr.com ...
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
Jul 18 '05 #14
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

Jul 18 '05 #15
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

Jul 18 '05 #16
Gregor Lingl <gl****@aon.at> wrote in news:3F**************@aon.at:
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 du****@rcp.co.uk
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?
Jul 18 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by flamesrock | last post: by
35 posts views Thread by Steven Bethard | last post: by
5 posts views Thread by Nicolas Couture | last post: by
2 posts views Thread by Rodney Maxwell | last post: by
18 posts views Thread by Alan G Isaac | last post: by
reply views Thread by Reedick, Andrew | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.