Put the module in a folder with associated
Calling the folder name in Python2 will fail directly
The call succeeds in Python3, but the call does not succeed
The solution is:
Add an empty file under this folder __init__.py Python2 will treat the folder as a package as a whole
Then edit __init__.py
Add __all__ = ["Function name 1", "Function name 2",...../or class name also line]
And then through from. Import Module Name
This makes it possible to invoke the module functions in the package.
#如果导入这个模块的方式是 from Module name import *, only the names contained in the __all__ list will be imported
A chestnut is clear:
Currently we have a package named Testmsg, which contains the following files:
1. Folder __pycache__:
__INIT__.CPYTHON-35.PYC:
160d 0d0a 0072 f058 2d00 0000 e300 00000000 0000 0000 0000 0002 0000 0040 00000073 1d00 0000 6400 0067 0100 5a00 00640100 6402 006c 0100 6d02 005a 0200 01640300 5329 04da 0773 656e 646d 7367 e901 0000 0029 0172 0100 0000 4e2972 0000 00a9 00720500 0000 7205 0000 00f5 4b00 00007079 7468 6f6e 2f44 65737974 686f 6e30 36e6 9c9f 2f707974 686f 6ee5 9fba e7a1 802d 31305465 73746974 5f5f 2e70 79da 083c 6d6f 6475
Sendmsg.cpython-35.pyc
160d 0d0a 356e f058 3100 0000 e300 00000000 0000 0000 0000 0002 0000 0040 00000073 1000 0000 6400 0064 0100 8400005a0000 6402 0053 2903 6300 0000 0000 00000000 0000 0002 0000 0043 0000 0073 0e000000 7400 0064 0100 8301 0001 6400 00532902 4e7a 162d 2d2d 2d73 656e 646d 73672d746573 7431 2d2d 2d2d 2d29 01da 05707269 6e74 a900 7202 0000 0072 0200 0000f54a0000 002f 686f 6D65 2f70 7974686f6e2f4465 736b 746f 702f 7079 74686f6e3036 e69c 9f2f 7079 74686f6e e59f bae7a180 2d31 302f3032 2de5 8c85 2f54 6573744d7367 2f73 656e 646d 7367 2e7079da0574 6573 7431 0100 0000 7302 0000 00000172 0400 0000 4e29 0172 0400 0000 72020000 0072 0200 0000 7202 0000 0072 03000000 Da08 3c6d 6f64 756c 653e 0100 00007300 0000 00
2.__init__.py
__all__ = ["sendmsg"]fromimport sendmsg
3.__init__.pyc
03f3 0d0a 0072 f058 6300 0000 0000 00000002 0000 0040 0000 0073 1d00 0000 64000067 0100 5a00 0064 0100 6402 006c 0100< /c0>0200 0164 0300 5328 0400 00007407 0000 0073 656e 646d 7367 6901 00000100 0000 5200 0000 004e 2803 000000 74 0700 0000 5f5f 616c 6c5f 5f74 00000000 5200 0000 0028 0000 0000 2800 00000028 0000 0000 7313 0000 0054 6573
744d
4.recvmsg.py
def test2 (): Print ("-----recvmsg-test2---")
5.sendmsg.py
def test1 (): Print ("----sendmsg-test1-----")
6.sendmsg.pyc
03f3 0d0a 356e f058 6300 0000 0000 00000001 0000 0040 0000 0073 0d00 0000 64000200 0000 5a00 0064 0100 5328 00006300 0000 0000 0000 0001 0000 0043 00000073 0900 0000 6401 0047 4864 0000 53280200 0000 4e73 1600 0000 2d2d 2d2d 73656 E64 6d73 672d 7465 7374 312d 2d2d 2d2d2800 0000 0028 0000 0000 2800 0000 00280000 0000 7312 0000 0054 6573 744D 7 3677367 2e70 7974 0500 00007465 7374 3101 0000 0073 0200 0000 00014e28 0100 0000 5200 0000 0028 0000 00002800 000 0 0028 0000 0000 7312 0000 00546573 744d 7367 2f73 656e 646d 7367 2e707974 0800 0000 3c6d 6f64 756c 653e 01000000 7300 000 0 00
We also have a file named infordisplay.py
def test3 (): Print ("-----infordisplay-test3----")
The arrangement is as follows:
Files under the Testmsg folder
Files under the __pycache__ folder
Source has given a pro-test effective advice to see this article students can try!!! I wish you all the best of your family and happiness study
Putting a module in a folder that is associated with the calling folder name in the Python2 will fail directly in the Python3, but the call will succeed, but the solution