Status of PEP's?

Emile van Sebille emile at fenx.com
Thu Feb 28 14:04:58 EST 2002


"Carel Fellinger"
> Emile van Sebille
> >     for ii in iter(len(mylist)):
>
> And how would this compare to
>
>       for ii in indici(mylist):
>

Interesting idea... I guess I was after something like:

class _dexedItem:
    def __init__(self, sequence, idx, idxname, idxnamespace):
        self.__dict__['sequence'] = sequence
        self.__dict__['idx'] = idx
        self.__dict__['idxname'] = idxname
        self.__dict__['idxnamespace'] = idxnamespace
    def __setattr__(self, attr, value):
        self.__dict__['sequence'][self.idx] = value
    def __del__(self):
        if
self.__dict__['idxnamespace'].has_key(self.__dict__['idxname']):
            self.__dict__['sequence'][self.idx] =
self.__dict__['idxnamespace'][self.idxname]
        else:
            self.__dict__['sequence'][self.idx] = None
    def __coerce__(self, other):
        return (self.__dict__['sequence'][self.idx],other)

class dexing:
    def __init__(self, sequence):
        import traceback, sys
        self.sequence = sequence
        self._idxname = traceback.extract_stack()[-2][3].split('in
dexing(')[0].split()[-1]
        frame = sys._getframe(-2)
        if frame.f_locals.has_key(self._idxname):
            self._idxnamespace = frame.f_locals
        else:
            self._idxnamespace = frame.f_globals
    def __getitem__(self, idx):
        if idx < len(self.sequence):
            return _dexedItem(self.sequence, idx, self._idxname,
self._idxnamespace)
        else:
            raise IndexError

mylist = range(5)

for ii in dexing(mylist):  # read as ' for ii in_dexing(mylist)'  ;-)
    ii *= 4

print mylist

Is __del__ protocol such as to reliably support this now?

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list