Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
MRO: copy, list
when i call mro in the following code it lists: (<class 'filledlist.FilledList'>, <class 'list'>, <class 'object'>)
why does it not contain copy instead of list? how does it default to list:
import copy class FilledList(list): def __init__(self, count, value, *args, **kwargs): super().__init__() for _ in range(count): self.append(copy.copy(value)) import filledlist from filledlist import FilledList fl = filledlist.FilledList(9,2) print(len(fl)) print(fl) print(FilledList.__mro__)
Chris FreemanTreehouse Moderator 68,227 Points
Good question. The use of a built-in or imported function does not make it part of the object.
The methods and attributes of
list become part of
FilledList along with the methods and attributes of
object that are part all objects.
copy were part of
FilledList you would be able to call it using
self.copy. Note that there is a
list.copy method but this returns a shallow copy of the whole list and does not make a copy of some other argument.
Post back if you need more help. Good luck!!