Hello there,
I am learning masking case when an object is instanced in a class and if
the name of the object and
method's name is same, Type error is raised.
the code is
class Bunch(object):
def __init__(self, *args, **kwargs):
for key, value in kwargs.items():
if hasattr(self, key):
raise AttributeError("API conflict: '%s' is part of the
'%s' API" % (key, self))
else:
setattr(self, key, value)
def pretty(self):
text = ""
for key, value in self.__dict__.items():
text += "%s: %s\n" % (key, value)
return text
if __name__ == "__main__":
b = Bunch(pretty=True)
The point is I don't know how to set up' *bunch.pretty = True* ' to prove
mistake in the following sentences below.
There, the code triggered a TypeError exception because the Bunch class's
pretty() method was *masked* by a data attribute on the instance, which we
then attempted to call. While the Bunch class now protects this from
happening during object instantiation, there is nothing to prevent you from
masking the pretty() method simply by setting *bunch.pretty = True* after
creating an instance.
Can you give me an example code how to prove nothing to prevent the code
from masking pretty() method
simple by setting *bunch.pretty=True*?
Thank you very much for your help!
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.