None, False, True

M

M-a-S

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.
 
I

Indigo Moon Man

M-a-S said:
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.(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.
 
A

anton muhin

Indigo said:
M-a-S said:
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.

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.
 
J

John J. Lee

M-a-S said:
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(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
 
M

Max M

M-a-S said:
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.

(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
 
S

Skip Montanaro

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
 
R

Raymond Hettinger

[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
 
M

M-a-S

anton muhin said:
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

M-a-S

Max M said:
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

Martin v. =?iso-8859-15?q?L=F6wis?=

M-a-S said:
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
 
S

Skip Montanaro

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
 
J

John Roth

M-a-S said:
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
 
M

M-a-S

Skip Montanaro said:
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:
False

Only the output will be
false


M-a-S
 
T

Terry Reedy

M-a-S said:
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
 
G

Gregor Lingl

M-a-S said:
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.

<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.0None

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?

----
.... pass
....
None

But:
.... return None
....3

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

Gregor Lingl

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.0None

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
 
D

Duncan Booth

Gregor Lingl said:
... pass
...
... return None
...
3

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

None

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top