# mymodule.py (Saved on disk)
def greeting(name):
print("Hello, " + name)
person1 = {"name": "John", "age": 36}
# main.py (In the same folder)
import mymodule
mymodule.greeting("Jonathan")
print(mymodule.person1["age"])
# You can alias the import
import mymodule as mx
print(mx.person1["name"])
DOWNLOADING CONCEPT: 1. MODULES & IMPORTS...
↳Consider a module to be the same as a code library.
↳A file containing a set of functions you want to include in your application.
↳You can use the import statement to pull in a module.
↳You can also rename it using the as keyword (import pandas as pd).
↳If you only need one specific function from a massive module, use the from keyword.
↳This saves memory and keeps your namespace clean.
▲ LIVE INCIDENTYou need to parse a JSON string received from an API.
sre@arena:~/python-modules
sre@arena:~$ python -c "import json; x = '{ \"name\":\"John\" }'; y = json.loads(x); print(y['name'])"