Classes: What is the standard trick for ...

Aahz Maruch aahz at netcom.com
Thu Jun 22 12:41:31 EDT 2000


In article <395235F9.94C0BBA1 at erols.com>,
Edward C. Jones <edcjones at erols.com> wrote:
>I would like to keep a collection of related functions together
>in a class:
>
>class functions:
>    def f1():
>        print 'f1'
>
>    def f2():
>        print 'f2'
>
>I would like a function call to look like "function.f1()". I
>would like to spare the user the need to create an instance of
>the class. Can I do this? How?

Use a module instead of a class.  I.e., create functions.py and require
the user to 'import functions'; then functions.f1() will work fine.
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"This is Usenet.  We're all masturbating in public places."  -DH



More information about the Python-list mailing list