0

kwargs need to be taken from function

Hi Please refer code below: It works fine for me till pchild2 object is created. This class constructor takes two arguments , one as class object of type parent and other rest all as kwargs in terms of key value pair. I have a method (testMethod) now working which creates like a kind of key value pair. But I am unable to use the same into child object constructor (I am trying this at pchild3) How to achieve the same? https://www.sololearn.com/en/compiler-playground/cR7Dp9qjVr8S

15th Mar 2024, 9:19 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Réponses
+ 2
1) testMethod returns type str. You should change return type. Example: ============================================ def testMethod(ch,value,dtype): test_dic={} key_str=str(ch) test_dic[key_str]={'value' :value, 'type': dtype} return test_dic =========================================== 2) I think it needs to be unpacked because of the nested structure of the dictionaries. Example: =========================================== pchild3 = child(pObj,**testMethod('B',2.5,'double')) =========================================== I fixed the above two places and it worked. Basically, the following usage would be better. =========== pchild1 = child(pObj,B=3,C=4) ===========
16th Mar 2024, 5:06 AM
Shugo
Shugo - avatar
0
Thanks
16th Mar 2024, 5:09 AM
Ketan Lalcheta
Ketan Lalcheta - avatar