In Python, the code for different functions is often written in different package, and when a package needs to import a method from another packageg (or call a function), it needs to import the module, otherwise python does not know the path of the imported module.
For example:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/88/5E/wKiom1fyUqaA8kAEAAAZ__d_uWw513.png "title=" 1.png " alt= "Wkiom1fyuqaa8kaeaaaz__d_uww513.png"/>
Below the Day4 object-oriented folder, there are three modules (backend, logic, config) and a python file (user.main.py)
The DB module and Logic module are included under the backend module. The logic module has a handle.py file with three functions defined in it:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/88/5E/wKiom1fyU3zBc166AABO-OuRB8U716.png "title=" 2.png " alt= "Wkiom1fyu3zbc166aabo-ourb8u716.png"/>
Now, user.main.py this file wants to invoke the home () function in the handle.py file below the logic module, how do I do it?
This can be written in the user.main.py file:
Import module:
From backend.logic import handle
Call Method:
Handle.home ()
#!/usr/bin/env python#-*-coding:utf-8-*-from backend.logic Import handlep1 = Handle.home () print P1 output: Welcome to Homepagenone
Attention:
Here you can import the handle file under the logic module, there is a precondition that there is a __init__ python file under the logic module, although the file content is empty, but if you delete the file, you cannot import it.
For an introduction to __init__, please refer to: http://blog.csdn.net/yxmmxy7913/article/details/4233420
This article is from the "Zengestudy" blog, make sure to keep this source http://zengestudy.blog.51cto.com/1702365/1858622
Python Custom Module Import