Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python static overloading of member function

Tags:

python

oop

I'm new to python and have a simple question: Is it possible to statically overload a member fuction? Like for example so:

class A:
    text=""
    def __init__(self, text):
        self.text = text

    def print(self):
        print (self.text)

    @staticmethod
    def print():
        print ("static")

a = A("test") 
a.print()

In this case "static" is printed out. Is it impossible to call the member function if a static function with the same name exists? And if not, who do I call it?

like image 804
cybertschunk Avatar asked Oct 29 '25 11:10

cybertschunk


1 Answers

You aren't overloading the method; you are replacing it with the static method. You'll have to pick a different name for the static method.

like image 163
chepner Avatar answered Oct 31 '25 01:10

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!