Can this be done?
Copy all names from a namespace and paste into another and overwrite same names?
There's an object __dict__ that is used to contain an object's objects
so if you have to objects a and b and want to put a.* into b without any checks, just iterate through the dictionary and copy the elements.
I don't know if it will work just like this(you need to add a few conditions so you dont overwrite things like b.__dict__ itself) but I hope you get the idea.Code:a = Object1()#can be anything, an instance, a module... b = Object2() #this will copy everything from a to b for elem_str in a.__dict__: b.__dict__[elem_str] = a.__dict__[elem_str]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks