473,513 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 18 '05 #1
5 8379
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.
Jul 18 '05 #2
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 && ma*@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
Jul 18 '05 #3
In article <3F***************@alcyone.com>,
Erik Max Francis <ma*@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
Jul 18 '05 #4
> 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

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2914
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
16
25393
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
2
1830
by: MLH | last post by:
Gentlemen: I have declared an array Dim MyTables(14) AS Long Now I want to assign values for MyTables(0) - MyTables(14) equal to the number of records in each table. Catch, I want the code...
15
26889
by: Swetha | last post by:
Hello I have a DropDownList that I am populating using the following SqlDataSource: <asp:DropDownList ID="parentIDDropDownList" runat="server" DataSourceID="SqlDataSource3"...
2
4763
by: Eugenio | last post by:
Sorry in advance for my english. :-) I have a form MS Access97 with two subforms. These subforms have different data and dimensions, if into the main form I've selected with checkbox "Date of...
2
4719
by: Michael Bohman | last post by:
Hi, i have a small problem with assigning a database value to a RadioButtonList control. On my form i have 3 user admin=1, premium=2 and basic=3, theese values is stored in an access database in a...
7
1473
by: aurora10 | last post by:
Hi, I have textfile with True or Flase in it and I need to read this file so that the value is assigned to a checkbox on the form. How can I do that ? Thanks:)
5
2555
by: =?Utf-8?B?RkxEYXZlTQ==?= | last post by:
I'm developing an application that gets data from 100 sources (via telnet connections, but you can think stock quotes from a webservice if you like). I was planning on using the thread pool (25...
2
2565
by: Constantine AI | last post by:
Hi i have created a Sales Order Header with a Sales Order Line (1 to many relationship) See Picture for image of error! I receive this error when inputting data into the sfrmSOHeader in Add mode. I...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.