I know how to set it in my /etc/profile and in my environment variables.
But what if I want to set it during a script? Is it import os, sys? How do I do it?
If you put sys.path.append('dir/to/path') without check it is already added, you could generate a long list in sys.path. For that, I recommend this:
import sys
import os # if you want this directory
try:
sys.path.index('/dir/path') # Or os.getcwd() for this directory
except ValueError:
sys.path.append('/dir/path') # Or os.getcwd() for this directory