Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class inheritance
#4
One problem with relying on named arguments is that you cannot use position arguments. You could not do this:
cap = Capacitor(ipn, mpn, dpn, manufacturer, dielectric)
Output:
TypeError: Capacitor() takes 1 positional argument but 5 were given
I've noticed some functions in the Python standard libraries that have this same problem/limitation.
Quote:random.choices(population, weights=None, *, cum_weights=None, k=1)
I cannot call random.choices like this:
c = random.choices(values, weights, None, 10)
"cum_weights" and "k" are name only arguments. This is enforced by "*" in the signature. If you want to use name-only arguments you could do the same.
Reply


Messages In This Thread
Class inheritance - by oclmedyb - Dec-06-2020, 05:00 PM
RE: Class inheritance - by deanhystad - Dec-06-2020, 11:01 PM
RE: Class inheritance - by oclmedyb - Dec-09-2020, 04:13 PM
RE: Class inheritance - by deanhystad - Dec-09-2020, 04:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  super() and order of running method in class inheritance akbarza 7 836 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  Child class inheritance issue eakanathan 3 1,407 Apr-21-2022, 12:03 PM
Last Post: deanhystad
  Importing issues with base class for inheritance riccardoob 5 4,795 May-19-2021, 05:18 PM
Last Post: snippsat
  3D vector class with inheritance from 2D vector class buss0140 4 3,208 Dec-20-2020, 08:44 PM
Last Post: deanhystad
  Can we access instance variable of parent class in child class using inheritance akdube 3 14,048 Nov-13-2020, 03:43 AM
Last Post: SalsaBeanDip
  Performance degradation with IO class inheritance wsygzyx 2 2,166 Jun-18-2020, 06:02 PM
Last Post: wsygzyx
  Confusion with sublcassing a threading class, and inheritance bigmit37 2 7,729 Apr-08-2019, 09:28 AM
Last Post: DeaD_EyE
  Class Attributes Inheritance Harry_Potter 3 3,895 Nov-16-2017, 07:01 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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