Cute 'proxy' with __new__

jerf at compy.attbi.com jerf at compy.attbi.com
Tue Dec 31 11:49:57 EST 2002


On Tue, 31 Dec 2002 00:13:50 +0000, Aahz wrote:

> In article <pan.2002.12.30.21.55.44.730039 at compy.attbi.com>,
>  <jerf at compy.attbi.com> wrote:
>>
>>    loadedFiles = {}
>>    def __new__(cls, filename, init = None):
>>        try: return cls.loadedFiles[filename]
>>        except: pass
> 
> You should update your try/except to catch specific exceptions; what
> happens if the user presses ctrl-C?

I said I deliberately left that out to shorten the code. Proper exception
handling would have doubled the length of the code (approx.), thereby
obscuring the point, and I already don't intend the posted code to be used
directly; it's not likely one would save one object to one file.



More information about the Python-list mailing list