Add directory to sys.path based on variable

Chris Angelico rosuav at gmail.com
Thu Jan 30 09:09:56 EST 2014


On Fri, Jan 31, 2014 at 1:03 AM, loial <jldunn2000 at gmail.com> wrote:
> In this case the import fails.
>
> import sys
> import os
> from os.path import *

Not sure why you need that, since you're explicitly naming
"os.path.dirname". The base "import os" shoul cover that for you.

> scriptpath=os.path.dirname(sys.argv[0])
> otherscriptspath=printerpath.replace("scripts","otherscripts")
> sys.path.append(otherscriptspath)

Try adding here:

print(sys.argv[0])
print(otherscriptspath)

See what they tell you. Is sys.argv[0] what you think it is? Is the
resulting path what you expect?

ChrisA



More information about the Python-list mailing list