473,499 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

injecting "set" into 2.3's builtins?


I use sets a lot in my Python 2.3 code at work and have been using this
hideous import to make the future move to 2.4's set type transparent:

try:
x = set
except NameError:
from sets import Set as set
else:
del x

Of course, while it's transparent at one level (where sets are used) it's
not really transparent at another level (where the set object is defined).

I'm toying with the idea of adding this to the sitecustomize module at work:

import sets
import __builtin__
__builtin__.set = sets.Set
del sets, __builtin__

I'm wondering if others have tried it. If so, did it cause any problems?
I've not noticed any incompatibilities between the 2.3 and 2.4 versions of
set objects, but my use of them has been pretty straightforward.

Thanks,

Skip

Jul 18 '05 #1
3 1516
Skip Montanaro wrote:
I use sets a lot in my Python 2.3 code at work and have been using
this hideous import to make the future move to 2.4's set type
transparent: try:
x = set
(Surely just 'set' on its own is sufficient? This avoids the ugly else
clause.)
__builtin__.set = sets.Set I'm wondering if others have tried it. If so, did it cause any
problems?


I don't know of any specific case where it would cause problems but I'd
be very wary of this; certainly doing the same with True and False has
caused problems in the past. A module might sniff for 'set' and assume
it is running on 2.4 if it sees it, with unpredictable results if it
relies on any other 2.4 behaviour.

I'd personally put this at the top of local scripts:

from siteglobals import *

Then put compatibility hacks like set and bool in siteglobals.py. Then
any modules or other non-site scripts could continue without the
polluted builtin scope.

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/

Jul 18 '05 #2

an********@doxdesk.com wrote:
Skip Montanaro wrote:
I use sets a lot in my Python 2.3 code at work and have been using
this hideous import to make the future move to 2.4's set type
transparent:
try:
x = set


(Surely just 'set' on its own is sufficient? This avoids the ugly

else clause.)
__builtin__.set = sets.Set
I'm wondering if others have tried it. If so, did it cause any
problems?


I don't know of any specific case where it would cause problems but

I'd be very wary of this; certainly doing the same with True and False has caused problems in the past. A module might sniff for 'set' and assume it is running on 2.4 if it sees it, with unpredictable results if it
relies on any other 2.4 behaviour.


Aarrgghh! When there's a documented API (sys.version_info) for
determining the version, such a module (and it's author) could be
charitably described as "broken". I can't imagine there are any on
Skip's site :-)

Jul 18 '05 #3
caused problems in the past. A module might sniff for 'set' and
assume it is running on 2.4 if it sees it, with unpredictable results
if it relies on any other 2.4 behaviour.


John> Aarrgghh! When there's a documented API (sys.version_info) for
John> determining the version, such a module (and it's author) could be
John> charitably described as "broken". I can't imagine there are any on
John> Skip's site :-)

Thanks for the vote of confidence (I think). Yes, I'd only inject "set"
into builtins on 2.3, and anyone who wants to do version-dependent things
should use some variant of sys.version_info.

Skip
Jul 18 '05 #4

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

Similar topics

2
1873
by: Phil Powell | last post by:
print_r("From index.php 20: $prefix: stateXML = $stateXML<P>"); foreach (array('state', 'country') as $prefix) { print_r("From index.php 21: stateXML = $stateXML<P>"); ${$prefix . 'XML'} =...
3
1720
by: Anthony Liu | last post by:
I want to use the set function like mylist = myset = set (mylist) But I don't know what to import, I tried sys, sets, they don't work. What's the easy way to find out the module that...
12
5720
by: Me | last post by:
Hi, I would like learn from people with experience in C++, which of the following styles of way to construct "get/set" member functions would be the best in terms of usability, speed, et cetera. ...
1
3895
by: J. Muenchbourg | last post by:
The following line in part of my asp-sql block: Set rs = Server.CreateObject("ADODB.Recordset") creates an application error: "Set" assignment statements are no longer supported (in this...
7
3578
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
2
2268
by: K Williams | last post by:
I recently discovered that you can do the following: if currentdb.openrecordset ("select statement.....").eof = true then for cases when you just want to see if any records exist. This...
10
17183
by: Mart | last post by:
What class does everyone out there use if they want to store a set of values efficiently? In java I use a HashSet, but there is no equivalent in C#. Even worse, the lowest level interface to...
1
5191
by: Gregor Horvath | last post by:
Hi, I searched the web and docs but cannot figure out whats wrong with this code: #!/usr/bin/python import Tkinter as Tk class testtk(Tk.Frame):
1
1973
by: slrj | last post by:
Can I use a local struct to store data in the "set" conatiner? If so, what is the correct method to do so? Compiler: Sun Studio 10 on Unix (Sun Solaris) #include<iostream> #include<set> ...
0
7132
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
7009
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
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
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
3103
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
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.