Use cases for del

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Wed Jul 6 16:23:03 EDT 2005


Ron Adam wrote:
> Ron Adam wrote:
> 
>> And accessing an undefined name returned None instead of a NameError?
> 
> I retract this.  ;-)
> 
> It's not a good idea.  But assigning to None as a way to unbind a name 
> may still be an option.

IMO, it isn't. This would completely preclude the usage of None as a value.
None is mostly used as a "null value". The most prominent example is default
function arguments:

def foo(bar, baz=None):

With None unbinding the name, what would you suggest should happen? baz being
undefined in the function scope?

Or, what should happen for

somedict[1] = None

The same as

del somedict[1]

? Also, the concept of _assigning_ something to a name to actually _unassign_
the name is completely wrong.

Of course, this is a possible way to unassign names if (and only if)
(1) there is a real "undefined" value (not None)
(2) unbound names return the undefined value

Look at Perl. Do we want to be like that? ;)

Reinhold



More information about the Python-list mailing list