Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of python Import Module

Shulou Source: shulou.com Published: 2022-06-03 17:36:11 10月04日 Update

This article mainly introduces the python import module example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.

1. Execute a .py file, open up new memory, and put the imported things into memory, so that you can get them directly from memory by calling.

2. When there are more and more modules, it is necessary to manage the modules through packages.

Example

# call in the package file (usually at the beginning of the import statement) import harryimport magicprint (harry.name) harry.Fight () c = harry.Course ('Harry') c.add_course ('Defense against the Dark Arts') magic.use_magic () # module rename import harry as hy # to prevent the module name from being too long to rename # import method 2from harryimport namefrom harryimport Fightfrom harryimport Courseprint (name) Fight () c = Course ('Harry') c.add_course ('Defense against the Dark Arts') # this method does not need to use harry. The method, which is equivalent to declaring the source in advance and simplifying the logic, can also play the role of introducing a specific variable and a specific function characteristic class. # from harry import name# from harry import Fight# from harry import Course can also use the following expression instead of simplifying the code from harry import name, fight, Course or from harry import * # to import everything into thank you for reading this article carefully. I hope the article "sample Analysis of python Import Module" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Modules articles memory methods examples analysis functions files magic Harry defense no things code values interests functions variables can be passed at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information MySQL Huawei Microsoft