say_hello("Wilbur")
from IPython.display import display,SVG
display(SVG('<svg height="100"><circle cx="50" cy="50" r="40"/></svg>'))
assert say_hello("Jeremy")=="Hello Jeremy!"
assert say_hello("Chris")!="Hello Jeremy!"
We can define an instance of the class HelloSayer by passing the appropriate parameters to the constructor (in this case a single string containing the object of prospective saying).
o = HelloSayer("Alexis")
It is possible to simply print the __dict__ associated to any instance of the object as:
print(o.__dict__)
This works even if there is no __str__ method defined. Otherwise, it is probably better to use the internally defined __repr__ and __str__ as:
print([o])
print(o)
print(o.to)
o.say()
If you just want a list of the methods associated to an object, you can use a list comprehension as:
def get_object_methods(object):
return [method_name for method_name in dir(object)
if callable(getattr(object, method_name))]
print(get_object_methods(o))
If it is necessary to get a comprehensive listing of the contents of an object, use the dir function as:
dir(o)
It is also possible to use the python inspect module to get more detailed information about the structure of an object:
import inspect
inspect.getmembers(o)
You can also simply call the help function on your instance.
?help
help(o)