Cute 'proxy' with __new__
Aahz
aahz at pythoncraft.com
Tue Dec 31 11:57:58 EST 2002
In article <pan.2002.12.31.11.49.26.575333 at compy.attbi.com>,
<jerf at compy.attbi.com> wrote:
>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.
Ah. Sorry, I missed that bit embedded in the postscript.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"There are three kinds of lies: Lies, Damn Lies, and Statistics." --Disraeli
More information about the Python-list
mailing list