How do I pass an extra argument "page_name
" when creating NotebookPage
object below? I get the error below:
class NotebookPage(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
NotebookPage(self, name='NotebookPage0', page_name=page)
TypeError: 'page_name' is an invalid keyword argument for this function
I need to pass page_name
argument when creating NotebookPage
object. But since page_name
is not a valid argument of wx.Panel
, I get that error.
You should remove additional argument from kwargs
before calling __init__
. For example with dict pop
method:
class NotebookPage(wx.Panel):
def __init__(self, *args, **kwargs):
page_name = kwargs.pop('page_name', None)
wx.Panel.__init__(self, *args, **kwargs)
if page_name:
# somehow using page_name here
In Python 3.x, you can simply mention the explicit kwarg before the other ones, like this:
class NotebookPage(wx.Panel):
def __init__(self, *args, page_name, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
print(page_name)
In older (2.x) versions of Python, this only works if there are no variable argument lists (*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