Finding members of module by using dir() function
- Python provides inbuilt function dir() to list out all members of current module or a specified module.
- dir() ===>To list out all members of current module
- dir(moduleName)==>To list out all members of specified module
Eg 1:
Eg 2: To display members of particular module
x=888
def add(a,b):
print("The Sum:",a+b)
def product(a,b):
print("The Product:",a*b)
Eg 3:
Based on our requirement we can access these properties also in our program.
Eg: test.py:
print(__builtins__ )
print(__cached__ )
print(__doc__)
print(__file__)
print(__loader__)
print(__name__)
print(__package__)
print(__spec__)
Output
<module 'builtins' (built-in)>
None
None
test.py
<_frozen_importlib_external.SourceFileLoader object at 0x00572170>
__main__
None
None
Comments
Post a Comment