# import os module
import os
os.getcwd()

# The following command provides the details of the imported package definition
# help(os.listdir())

"""
Explanation: Modules and Packages
Modules
A module is simply a file containing Python definitions, functions, and statements. Putting code into modules is useful because of the ability to import the module functionality into your script.
Module helps to keep everything modular and separate. For instance many modules have a read() function since this is a common thing to do. Without using the &lt;module>.<function&gt; (...) syntax there would be no way to know which one to call.
End of explanation
"""


# save the following code as example.py
def add(a,b):
    return a+b

# now you can import example.py
# import example
# example.add(5,4)

"""
Explanation: User Defined Module
End of explanation
"""


import math as m
print(m.pi)

"""
Explanation: Import with renaming
We can import a module by renaming it as follows:
End of explanation
"""


from math import pi
print(pi) # please note the dot operator is not required

"""
Explanation: from...import statement
We can import specific names from am module without importing the full module.
End of explanation
"""


from math import *
print(pi)

"""
Explanation: To import all definitions from the module just specify '*' as below. Please note that this not a good practice as it can lead to duplicate definitions for an identifier.
End of explanation
"""


import sys
sys.path

"""
Explanation: Module Search Path
While importing a module python looks for a definition at various places and in the following order.

First it looks for a built-in module
Looks at the current directory
PYTHONPATH ( environment variable with a list of directory )
Installation dependent default directory
End of explanation
"""


# my_module.py
# print('This code got executed')

# import imp
# import my_module
# This code got executed
# import my_module
# import my_module
# imp.reload(my_module)

"""
Explanation: Reloading a Module
Python loads modules only once even though you try to import it multiple times. But if the module is changed for some reasons and you want to reload the module you can use the .reload() function inside the 'imp' module.
End of explanation
"""


print(dir(os))

import math
print(math.__doc__)
math.__name__

"""
Explanation: Module Functions
End of explanation
"""


# examples
import math
from math import pi
print(pi)

"""
Explanation: Packages
A package is just a way of collecting related modules together within a single tree-like hierarchy.
Like we organise the files in directories, Python has packages for directories and modules for files. Similar, as a directory can contain sub-directories and files, a python package can have sub-package and modules.
A directory must contain a file named __init.py in order for python to consider the directory as a package. This file can be empty but in general it is used for initialisation code for that package.
The following are different ways of importing the packages.

import &lt;package name&gt;
import &lt;package name&gt;.&lt;module name&gt;
from &lt;package name&gt; import &lt;module name&gt;
End of explanation
"""


