In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces you how to introduce import and from... import, the content is very detailed, interested friends can refer to reference, I hope to help you.
Generally import and from... import... Import module.
Take the file code in spam.py below as an example.
import module name
import Three things happen when you import a module for the first time:
Create a module namespace based on the module
Execute the file corresponding to the module, and throw the names generated during execution into the module namespace.
Get a module name in the current execution file
Duplicate imports of modules create good results directly before drinking, and do not execute the module's files repeatedly, i.e. duplicate imports occur: spam=spam= memory address of the module namespace
from module name import specific function
from... import... Three things happen when you import a module for the first time:
Create a module namespace based on the module
Execute the file corresponding to the module, and throw the names generated during execution into the namespace of the module in the namespace of the currently executed file.
Get a name in the module, which directly points to a name in the module, meaning that you can use it directly without adding any prefix.
Advantages: No prefix, code is more streamlined
Disadvantages: Easy to conflict with names in the namespace in the current execution file
mport and from... import... the similarities and differences
Same points:
Both execute the file corresponding to the module, both generate the namespace of the module, and when calling the function, you need to go to the definition to find the scope relationship, regardless of the calling location.
Difference:
import requires prefix;from... import... No prefix required
About how to introduce import and from... import to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.