Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65006

Re: Add directory to sys.path based on variable

References <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> <mailman.6128.1391085772.18130.python-list@python.org> <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com>
Date 2014-01-31 01:09 +1100
Subject Re: Add directory to sys.path based on variable
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.6140.1391091007.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jan 31, 2014 at 1:03 AM, loial <jldunn2000@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Add directory to sys.path based on variable loial <jldunn2000@gmail.com> - 2014-01-30 04:39 -0800
  Re: Add directory to sys.path based on variable Tim Golden <mail@timgolden.me.uk> - 2014-01-30 12:42 +0000
    Re: Add directory to sys.path based on variable loial <jldunn2000@gmail.com> - 2014-01-30 06:03 -0800
      Re: Add directory to sys.path based on variable Chris Angelico <rosuav@gmail.com> - 2014-01-31 01:09 +1100
      Re: Add directory to sys.path based on variable Tim Golden <mail@timgolden.me.uk> - 2014-01-30 14:14 +0000
        Re: Add directory to sys.path based on variable loial <jldunn2000@gmail.com> - 2014-01-30 06:26 -0800

csiph-web