I am programming in Python 2.7. In other languages like Ruby, there is an invocation of super
in a method such that one does not need to specify the parameters with which to call super
-- super
. One omits the parameters in one's super
call and the given super method is invoked with the same parameters as one's given method was called.
Here is an example from the StackOverflow question Super keyword in Ruby:
class Foo
def baz(str)
p 'parent with ' + str
end
end
class Bar < Foo
def baz(str)
super
p 'child with ' + str
end
end
Bar.new.baz('test') # => 'parent with test' \ 'child with test'
As you can see the method baz
in the class
Bar
contains the invocation of super
without any parameters and the super method baz
in the super class Foo
implicitly gets called with the same parameter(s) as the method baz
in the child class Bar
For a variety of reasons this is very convenient, and while obviously implicit behavior in programming has its drawbacks, it is really useful to be able to have an __init__
method in a child class that does stuff in that child class and then invokes __init__
via super
without having to know the parameters for __init__
in the super class.
Please help, any advice would be useful. I have been searching for an answer and unable to find one. I have seen many questions and answers on StackOverflow about super
and super
in __init__
and super
in Python, but nonw about whether there is syntax for calling super
that does not require parameters to be specified and calls it with the same parameters as the given method was called in the child class.
What I am trying to do is very similar to raise
in a try
, except
, raise
construct in Python:
try:
linux_interaction()
except Exception as error:
logger.critical(str(error))
raise
In the above block I catch all exceptions, I log any exception as critical and then I throw it with just a call to raise
, no parameters. That calling syntax of raise
with no parameters causes the exception that was caught in the variable named error
to be thrown and preserves the calling stack/stack trace. If one called raise error
instead of just raise
, then the stack trace from where the error
originated would be lost.
I am trying to do something similar here, just invoke super
and get the super method invoked with the same parameters as the given method without needing to know what they are and without needing to specify them -- that would be convenient, right?
Anyone know if this is possible and if so what the syntax in Python 2.7 would be?