2001 Enchancement Wishlist
Raymond Hettinger
othello at javanet.com
Fri Dec 29 14:49:31 EST 2000
If these ideas meet with favor, I'll write-up a PEP.
1. List.append(elem) and List.pop() are great. Let's add two more
methods, List.prepend(elem) and List.leftpop(). The goal is to
make queues,deques, and reverse stacks easier, faster, and clearer
to implement.
2. There is already a PEP to extend the eval() function which is currently
limited to dictionaries. The goal is to accept any object defining
__getitem__() so that any mapping object can be used to specify the
globals and locals. I recommend that we extend the same courtesy to
the % string formatting operator. For example:
print "Spam with %s, eggs, and spam" % aUserDictionary
3. __init__ is the only special method that doesn't allow a return value.
I think it should continue to return the new object by default but also
allow another return item to be substituted. For example:
def __init__( self ):
if MyClass.aSingleton == None:
MyClass.aSingleton = self
return MyClass.aSingleton
4. Allow dictionaries to respond to sequence operations as if .keys() were
in the list object. Examples:
knights = { 'lancalot':'good', 'gallahad':'brave', 'robin':'coward' }
for name in knights:
print name, knights[name]
print knights.len()
if 'arthur' in knights:
print 'Not the King'
print knights[0] # may be any one depending on the hash table
order
try:
print knights[5]
except IndexError:
print 'Too few knights for the ladies in the castle'
del knights['lancelot'] # regular mapping operations left unchanged.
I believe all of the enhancements can be added without impacting existing
programs.
Hope suggestion #4 isn't too radical.
Happy New Year,
Raymond Hettinger
othelloNOSPAM at javanet.com
More information about the Python-list
mailing list