Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Assign to True / False in 2.3 (http://www.velocityreviews.com/forums/t319121-assign-to-true-false-in-2-3-a.html)

Culley Angus 07-02-2003 09:39 AM

Assign to True / False in 2.3
 
Just downloaded the latest beta of 2.3, and having a bit of fun playing
with the new goodies, lovely work by the way :)

I was a little suprised to find that I could assign a value to 'True',
and 'False' without warning though, and was wondering if this is deliberate.

For example:
if (1 == True): print "true"
True = 0
if (1 == True): print "true"
else: print "true is false"

This snippet is fairly unlikely to ever be written by a sober
individual, but if something similar is constructed by accident, the
repercussions may be interesting if not detected.

Can True (or False for that matter) be relied on for this sort of direct
comparison?.


Erik Max Francis 07-02-2003 10:02 AM

Re: Assign to True / False in 2.3
 
Culley Angus wrote:

> I was a little suprised to find that I could assign a value to 'True',
> and 'False' without warning though, and was wondering if this is
> deliberate.


This is true of pretty much all Python features. The only special
dispensation goes to None, which is a warning now (in the 2.3 beta):

Python 2.3b2 (#1, Jun 29 2003, 20:30:58)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> None = 0

<stdin>:1: SyntaxWarning: assignment to None

Python takes the approach of "We're all adults here." If you're using
Python, it presumes that you don't need handholding, and that you won't
do things you know you shouldn't do. For instance, imagine the havoc
that things like this would cause:

>>> int = float
>>> file = str
>>> sys = 'This is really not a module'


--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Shooters, looters / Now I got a laptop computer
\__/ Ice Cube

Just 07-02-2003 10:38 AM

Re: Assign to True / False in 2.3
 
In article <3F02ADD3.6047F561@alcyone.com>,
Erik Max Francis <max@alcyone.com> wrote:

> Culley Angus wrote:
>
> > I was a little suprised to find that I could assign a value to 'True',
> > and 'False' without warning though, and was wondering if this is
> > deliberate.

>
> This is true of pretty much all Python features. The only special
> dispensation goes to None, which is a warning now (in the 2.3 beta):


Actually, at some point there was a warning for True and False as well,
but it was taken out because there is plenty of code out there like this:

try:
True, False
except NameError:
True, False = 1, 0

(I'm not entirely sure, it can also be that there never was a warning in
place, but it was discussed.)

Just

Max M 07-02-2003 12:27 PM

Re: Assign to True / False in 2.3
 
> Culley Angus wrote:

> This is true of pretty much all Python features. The only special
> dispensation goes to None, which is a warning now (in the 2.3 beta)



I most often use this freedom to overwrite "id". I Guess that it's a bad
Zope habbit...

regards Max M


Andrew Bennetts 07-02-2003 12:59 PM

Re: Assign to True / False in 2.3
 
On Wed, Jul 02, 2003 at 03:02:59AM -0700, Erik Max Francis wrote:
> Culley Angus wrote:
>
> > I was a little suprised to find that I could assign a value to 'True',
> > and 'False' without warning though, and was wondering if this is
> > deliberate.

>
> This is true of pretty much all Python features. The only special
> dispensation goes to None, which is a warning now (in the 2.3 beta):
>
> Python 2.3b2 (#1, Jun 29 2003, 20:30:58)
> [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> None = 0

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


Incidentally, the reason why a SyntaxWarning isn't raised for True and False
is that there is a lot of existing code for older pythons that do tricks
like:

True = (1 == 1)
False = not True

Or something similar, and the Python team didn't want to break code, or
cause spurious warnings for code that might otherwise work perfectly well
with 2.3 and 2.2 or even 1.5.2 (depending on what else it did, of course).

-Andrew.




All times are GMT. The time now is 06:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.