import inspect
import pprint
data_str = 'my data'
#returns a list of method/function names for data_str object
data_str_methods = inspect.getmembers(data_str, inspect.isfunction(data_str))
pprint.pprint(data_str_methods)
def hello_world():
'''returns hello world string'''
return 'hello world'
# stores hello_world source code
hello_world_source_code = inspect.getsource(hello_world)
print(hello_world_source_code)
# output
# def hello_world():
# '''returns hello world string'''
# return 'hello world'
print(inspect.getdoc(print))
# output
# print(value, ..., sep=' ', end='
', file=sys.stdout, flush=False)
#
# Prints the values to a stream, or to sys.stdout by default.
# Optional keyword arguments:
# file: a file-like object (stream); defaults to the current sys.stdout.
# sep: string inserted between values, default a space.
# end: string appended after the last value, default a newline.
# flush: whether to forcibly flush the stream.