Classes: What is the standard trick for ...
Erno Kuusela
erno at iki.fi
Sat Jun 24 14:42:32 EDT 2000
>>>>> "Edward" == Edward C Jones <edcjones at erols.com> writes:
Edward> I would like a function call to look like
Edward> "function.f1()". I would like to spare the user the need
Edward> to create an instance of the class. Can I do this? How?
you could make it a module (in a package, perhaps). or you could
create the instance yourself, for example like this..
class _functions:
def f1(self):
return 'spam'
functions = _functions()
now the users of your module can call yourmodule.functions.f2()
and get spam without needing to instantiate anything themselves.
-- erno
More information about the Python-list
mailing list