2

I'd like to create an object to regroup a set of functions (a sort of toolbox), tough I did not find how to create an object without creating a class. So, is it OK to create a class, let's say named Toolbox, such as Toolbox.tool1(x) applies a certain function to x, but Toolbox() gives an error ?

Otherwise, do you have any suggestion ?

Naeio
  • 1,112
  • 7
  • 21

1 Answers1

2

What about

class Toolbox(object):

  @property
  def __init__(self):pass

  @staticmethod
  def tool1(x):
    return x

When trying to instantiate Toolbox, i.e. doing Toolbox(), you will get an error, as desired, because of the property decorating function, see

>>> Toolbox()
Traceback (most recent call last):
  [...]
TypeError: 'NoneType' object is not callable

and static methods can be used as usual, e.g.

>>> Toolbox.tool1(2)
2
keepAlive
  • 6,369
  • 5
  • 24
  • 39