Import From Module, importing only parts
- Details
- Category: Uncategorised
- Published: Tuesday, 06 July 2021 06:57
- Written by Super User
- Hits: 771
You can import only parts from a module, by using the from
keyword.
Example
The module named mymoduleexample
has one function and one dictionary:
def hello(name):
print("Hello, " + name)
employee1 = {
"name": "Vijay Singh",
"salary": 36000,
"country": "India"
}
now Import only the person1 dictionary from the module:
from mymoduleexample import employee1
print (employee1["salary"]) #no need to use the module name when referring to elements in the module