Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does python reference the Python module

2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to quote the Python module from python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Import statement

The custom module can be introduced using the import statement. The operation step is to import the module first, and then call the functions contained in the module. You can put the custom module into the current directory to facilitate path search of the interpreter. The following is an example of importing a custom hello.py module and calling the World function:

#! / usr/bin/python

#-*-coding: UTF-8-*-

# Import module

Import hello

# now you can call the functions contained in the module

Support.print_func ("World")

The output is as follows:

Hello World!

From can also be used for the above examples. Import is implemented by importing the specified part from a module into the current namespace. The above functions can be written as follows:

#! / usr/bin/python

#-*-coding: UTF-8-*-

From hello import World

If you want to import everything in the module into the current namespace, you can use from... The method of import*. Specific examples are as follows:

#! / usr/bin/python

#-*-coding: UTF-8-*-

From hello import *

Also note that when you import a module, the Python interpreter searches the location of the module in the following order:

1. Current directory

two。 If it is not in the current directory, Python searches each directory under the shell variable PYTHONPATH

3. If neither is found, Python looks at the default path.

This is the end of the content of "how to quote the Python module from python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report