Superclass static method name from subclass
Lars Liedtke
lal at solute.de
Fri Nov 11 11:46:46 EST 2022
yes,
just use SubClass.foo
at least this works for me:
class SuperClass:
@staticmethod
def test():
print("yay")
class SubClass(SuperClass):
def __init__(self):
super().__init__()
SubClass.test()
subclass = SubClass()
Output:
python3.11 test.py
yay
Cheers
Lars
Lars Liedtke
Software Entwickler
[Tel.] +49 721 98993-
[Fax] +49 721 98993-
[E-Mail] lal at solute.de<mailto:lal at solute.de>
solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany
[Logo Solute]
Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]
Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798
Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php
Am 11.11.22 um 17:21 schrieb Ian Pilcher:
Is it possible to access the name of a superclass static method, when
defining a subclass attribute, without specifically naming the super-
class?
Contrived example:
class SuperClass(object):
@staticmethod
def foo():
pass
class SubClass(SuperClass):
bar = SuperClass.foo
^^^^^^^^^^
Is there a way to do this without specifically naming 'SuperClass'?
More information about the Python-list
mailing list