This repository was archived by the owner on Mar 29, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 3535 ``` python
3636 a_object = a.getObj()
3737 ```
38+
39+ To add a method to the object (can also be used to refresh the object after the dictionary is changed):
40+ ``` python
41+ # define your method as a normal function
42+ def a_print ():
43+ print (" A is for apple" )
44+
45+ # add the attribute
46+ a.addAttr(" printA" , a_print)
47+
48+ # refresh the object
49+ a_object = a.getObj()
50+
51+ # call the method (optional)
52+ a_object.printA()
53+ ```
Original file line number Diff line number Diff line change 77 "juice_level" : 100
88})
99
10+ # Add attr
1011idealApple .addAttr ("green" , True )
1112print (idealApple )
1213
14+ # Change existing attr
1315idealApple .setAttr ("juice_level" , 75 )
1416print (idealApple )
1517
18+ # Remove attr
1619idealApple .delAttr ("will_make_teeth_fall_out" )
1720print (idealApple )
1821
19- print (idealApple .getObj ())
22+ # Get/refresh the object
23+ appleObj = idealApple .getObj ()
24+ print (appleObj .crunchy )
25+
26+ # Add method
27+ def applePrint ():
28+ print ("I love apples" )
29+
30+ idealApple .addAttr ("apples" , applePrint )
31+ appleObj = idealApple .getObj ()
32+ appleObj .apples ()
You can’t perform that action at this time.
0 commit comments