简体   繁体   中英

How to implement abstract class methods as static method in inherited class in python?

I am working on python 2.7. I need to implement a class having abstract method. All the methods of this class should be implemented as static method.

Example:-

from abc import ABCMeta, abstractmethod


class HelperABC(object):

    __metaclass__ = ABCMeta

    @abstractmethod
    def method_name(my_message):
        pass

In the above class i need to take method_name(my_message) and implement it as static method.

I want to use it as:-

@staticmethod
def method_name(my_message):
   "code"

Please tell me how to implement it.

I try to put both decorator @staticmethod and @abstractmethod like following:-

@abstractmethod
@staticmethod
def method_name(my_message):
    pass

This also did not work.

Modify your method as below. I tried and it worked for me:

@staticmethod
@abstractmethod
def method_name(my_message):
    pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM