Python Forum
How do I instantiate a class with **kwargs?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I instantiate a class with **kwargs?
#7
Buran was right, you wanted to use kwargs to pass along arguments to a superclass. I totally misread your intentions. Sorry.

Using **kwargs for subclassing works great. Just declare you new named arguments and pass **kwargs to the superclass.
class MyRrule(dateutil.rrule):
    def __init__(self, new_arg=None, **kwargs):
        super().__init__(**kwargs)
        self.new_arg = new_arg
Reply


Messages In This Thread
RE: How do I instantiate a class with **kwargs? - by deanhystad - Feb-16-2023, 06:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  kwargs question Jeff_t 8 3,109 Feb-16-2022, 04:33 PM
Last Post: Jeff_t
  Misunderstanding kwargs? Donovan 2 2,314 Aug-04-2020, 08:09 PM
Last Post: Donovan
  **kwargs question DPaul 10 4,515 Apr-01-2020, 07:52 AM
Last Post: buran
  Unpacking dictionary from .xlsx as Kwargs etjkai 5 2,941 Dec-27-2019, 05:31 PM
Last Post: etjkai
  opts vs kwargs Skaperen 4 2,540 Nov-30-2019, 04:57 AM
Last Post: Skaperen
  Python 3.5 Instantiate and manipulate object with multiprocessing jipete 1 4,897 Dec-28-2016, 12:46 AM
Last Post: micseydel
  create dictionary from **kwargs that include tuple bluefrog 2 4,929 Oct-26-2016, 10:24 PM
Last Post: Larz60+
  How do you use *args and **kwargs? Gengar 3 19,995 Sep-20-2016, 04:22 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020