I came across the folloqing type of code when looking for some pyQt examples :
class DisplayPage(QWizardPage):
def __init__(self, *args):
apply(QWizardPage.__init__, (self, ) + args)
What does *args mean ?
What is the purpose of using apply for this type of code ?
*args means that __init__ takes any number of positional arguments, all of which will be stored in the list args. For more on that, see What does *args and **kwargs mean?
This piece of code uses the deprecated apply function. Nowadays you would write this in one of three ways:
QWizardPage.__init__(self, *args)
super(DisplayPage, self).__init__(*args)
super().__init__(*args)
The first line is a literal translation of what apply does (don't use it in this case, unless QWizardPage is not a new-style class). The second uses super as defined in PEP 367. The third uses super as defined in PEP 3135 (works only in Python 3.x).
DisplayPage inherits from QWizardPage. Its constructor accepts a variable amount of arguments (which is what *args means), and passes them all to the constructor of its parent, QWizardPage
It's better to say:
super(DisplayPage, self).__init__(*args)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With