Anonymous class question
Dan Williams
dan at osheim.org
Wed Aug 6 21:42:28 EDT 2003
Python experts,
Is there a more pythonic way to do something evquilent to what this line
does without creating a dummy class?
self.file = type("", (object,), {'close':lambda slf: None})()
As you can guess, I want a dummy object that I can call close on with
impunity.
I've been reading _Python in a Nutshell_ (Thanks, Alex!), which defines
a Bunch class that I think could also work, but if I'm only going to use
it to define a class with a dummy close() method, I might as well just
create the dummy class with the dummy method. . . Unless there is
something equvilent to Bunch in one of the standard modules that I don't
know about . . .?
More information about the Python-list
mailing list