Python:Module
lastmod 2022-05-26created 2015-04-145 edits
Importing packages
To run the echo_test function in /home/user/python/game/sound/echo.py, add the /home/user/python/ directory to the PYTHONPATH environment variable:
First method
You can import the echo module and run it as follows.
Second method
You can use from ... import down to the directory containing the echo module and run it as follows.
Third method
You can import the echo_test function of the echo module directly and run it as follows.
Importing with relative paths
When using <cdoe>.</code>, you need to put one space after it.
import path
When using import, an error message similar to the one below may be printed.
Traceback (most recent call last):
File "/usr/local/bin/scons", line 188, in <module>
import SCons.Script
ImportError: No module named SCons.Script
This happens because Python cannot read the import path list; add the path to the PYTHONPATH environment variable.
Favorite site
Pages that link here