I've recently been experimenting with the use of class methods to get a better understanding of object-oriented programming. As part of a sample program I've got a short class called circle
, which can be used to create different circle
instances.
class circle():
def __init__(self):
self.radius = 10
self.color = 'blue'
def change_color(self, color):
self.color = color
@classmethod
def red_circle(cls):
circle.radius = 10
circle.color = 'red'
return cls
I've added in the class method red_circle
so that I can have a different default setting for circle
instances. The problem I have is that when I use the red_circle
method, the instance created is placed inside of mappingproxy()
? For example:
circle_one = circle()
circle_one.__dict__
Gives the output:
{'radius': 10, 'color': 'blue'}
But using
circle_two = circle.red_circle()
circle_two.__dict__
Gives:
mappingproxy({'__dict__': <attribute '__dict__' of 'circle' objects>,
'__doc__': None,
'__init__': <function __main__.circle.__init__>,
'__module__': '__main__',
'__weakref__': <attribute '__weakref__' of 'circle' objects>,
'change_color': <function __main__.circle.change_color>,
'color': 'orange',
'radius': 10,
'red_circle': <classmethod at 0x7f0e94ab1a10>})
Is there a way that I can manipulate circle_two
so that it appears the same as the circle_one
instance? It's not causing any problems right now, but it would be good to understand what's going on with the mappingproxy()
.