Computer science: a note about method chaining
Self-tutoring about calling methods in object-oriented programming: the tutor mentions an error.
Sometimes one might mean to chain methods such as
new_ob=f1().f2().f3()
but get an error like “the function f2 has no attribute f3”. Such an error might happen because the parentheses on f2 have been forgotten:
new_ob=f1().f2.f3()
Without its parentheses, f2 hasn’t been called, so can’t return an object which contains the method f3. Likely, one wants, as above,
new_ob=f1().f2().f3()
Source:
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.
Leave a Reply
You must be logged in to post a comment.