Aahz wrote:
In article <[EMAIL PROTECTED]>,
Ben Finney  <[EMAIL PROTECTED]> wrote:
Steven D'Aprano <[EMAIL PROTECTED]> writes:

I'd like to be able to call [a class] as if it were a function.
Normally calling a class object returns an instance -- I wish to
return something else.
In that case, you *don't* want a class at all; the entire point of a
class is to define behaviour for instances.

Absolutely agreed with your first clause, disagreed about the second
clause.  As I said earlier, the main point of a class singleton is to get
the effect of a module singleton without the need to create another file
on disk.

In 3.0, at least, one does not need a disk file to create a module.

>>> import types
>>> me = types.ModuleType('me') # type(__builtins__) works, no import
>>> me
<module 'me' (built-in)>
>>> me.a = 1
>>> me.a
1
>>> me.a + 1
2

That said, a blank class is even easier, and the representation is better.

tjr

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to