Save a hello.py file in the F:/data/python directory
>>> def hello (x): print X
>>> Import sys>>> sys.path.append (' F:/data/python ') #添加路径 >>> import hello>>> Hello.hello (5) #调用5
Do not change sys.path import custom module:
The first method: 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!
The second method: Add the F:/data/python path to the environment variable (in the system variable, add the Pythonpath variable, and add the path to the value)
>>> Import sys>>> Import hello>>> Hello.hello (1) 1