In the previous discussion, we assumed that all our programs are saved under our default directory, that is, Python33
in C:
or other similar directories. Obviously, it is not convenient if we plan to save our Python programs for a specific project under our designated directory. Assume that all of our programs related to our investment courses are located at C:\yan\Teaching\Python_for_Finance\codes_chapters\
. To include it in our path, we have the following Python code:
import sys myFolder="C:\\Yan\\Teaching\\Python_for_Finance\\codes_chapters" if myFolder not in sys.path: sys.path.append(myFolder)
To double check, we use the print(sys.path)
command, as shown in the following code:
>>>import sys >>>print(sys.path) ['', 'C:\\Python33\\Lib\\idlelib', 'C:\\windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages', 'C:\\Yan\\Teaching\\Python_for_Finance...