This article introduces how to use the python custom module to save a hello. py file in the F:/data/python directory.
>>> def hello(x): print x
>>> Import sys >>> sys. path. append ('F:/data/Python') # Add path >>> import hello >>> hello. hello (5) # Call 5
Import the custom module without changing sys. path:
Method 1: place the hello2.py file in the D:/Python27/lib/site-packages directory.
>>> import sys,pprint>>> pprint.pprint(sys.path)['', 'D:\\Python27\\Lib\\idlelib', 'F:\\data\\s', 'D:\\Python27', 'C:\\Windows\\system32\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\\lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27\\lib\\site-packages']>>> import hello2>>> hello2.hello()hello,world!
Method 2: Add the F:/data/python path to the environment variable (in the system variable, add the PYTHONPATH variable, and then add the path to the value)
>>> import sys>>> import hello>>> hello.hello(1)1
The above is a detailed description of the use of the python custom module. For more information, see other related articles in the first PHP community!