Add directory to sys.path based on variable

Tim Golden mail at timgolden.me.uk
Thu Jan 30 07:42:49 EST 2014


On 30/01/2014 12:39, loial wrote:
> I want to add a path to sys.path based upon a variable
> 
> Can I do that?
> 
> Hardcodeing the path works fine, but I want to set it based upon a
> variable.
> 
> I know I can set PYTHONPATH, but just wondering if I can add a
> directory on the fly to sys.path using a variable

Certainly:

<code>
import sys

newpath = "c:/users/tim/modules"
sys.path.append(newpath)

</code>


TJG



More information about the Python-list mailing list