473,769 Members | 1,618 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 incompatibiliti es 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 1529
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*@doxd esk.com
http://www.doxdesk.com/

Jul 18 '05 #2

an********@doxd esk.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_in fo) 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_in fo) 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_inf o.

Skip
Jul 18 '05 #4

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

Similar topics

2
1887
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'} = $this->getXML($prefix . '.xml'); } I have never seen anything like this in my 3+ years of PHP coding! When I ran this code, I get the following output:
3
1734
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 contains a particular function?
12
5755
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. The following class with be used as an example: class MyClass { public: // member function would go here. private: int data_;
1
3917
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 particular block): <% Dim rs, strSQLd
7
3607
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 example, consider this four-bit number: 1100 from this number I want to extract two numbers: 1000 and 100 had the four-bit number been 0101 I would want to extract 100 and 1. How should I do this? I wish I had some code to post but I don't...
2
2283
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 obviously does not assign the recordset to any variable. My question is, does this still use memory that is not freed because there is no "recset.close" and "set variable = nothing"?
10
17216
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 define the Add, Contains and Remove methods is an IList, and we all should know that a set isn't a list. ICollection only defines Count and CopyTo, which isn't useful at all. So even if I want to write my own Set implementation, what interface...
1
5237
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
1994
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> using namespace std;
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5298
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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 we have to send another system
2
3561
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.