Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)
recategorized by

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 ?

1 Answer

0 votes
by (25.1k points)

You can do it by decorating the __init__ function with @property decorator and the tool1 method with @staticmethod decorator.

class Toolbox(object):

  @property

  def __init__(self):pass

  @staticmethod

  def tool1(x):

    return x

Browse Categories

...