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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'explicitly': 0.05; 'sys': 0.07; 'os.path': 0.09; 'skip:o 60': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'fails.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'naming': 0.16; 'subject:Add': 0.16; 'subject:based': 0.16; 'subject:variable': 0.16; 'sys.argv[0]': 0.16; 'wrote:': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; '31,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'is?': 0.30; 'message-id:@mail.gmail.com': 0.30; 'fri,': 0.33; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'that,': 0.38; 'sure': 0.39; 'skip:p 20': 0.39; 'tell': 0.60; "you're": 0.61; 'you.': 0.62; 'here:': 0.62; 'shoul': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=hcpWjR4V0dXkDGDkGv+FnHBTicISKNBpiPhPZSdmNFE=; b=TgTFgP6PybAwP4xdG2J1IfQsyvczECLvbvaWG8qCp9rQjHjUavVdIHWFNUm32v3hkK fSSS7kUzX1v2KB3TjK3XbgwiSTkR4m8kozKD2WTuW9HNuPUyOI3dLnxj3EXD1WSgFQ2j fXdCM7arGAomN2Muu7vaswkBVNrJ6iLrs4WQGDF39ZA8eGZifIxnlTYWMf1sSJzKDrbv PQRo7KBAylW+8wX/NYU+olv2CIvTL9UkaEBMiHKQQBuKMCqpZ+07RTG3DMUbr/Iuckhz PN3+7TyfCsmexrrRVwukgtHE2143ByWFUOLGk8X6pvMyFhAFUysFfY7naAVITzr6mKgE 1S2g==
MIME-Version 1.0
X-Received by 10.68.98.3 with SMTP id ee3mr14671199pbb.31.1391090996149; Thu, 30 Jan 2014 06:09:56 -0800 (PST)
In-Reply-To <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com>
References <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> <mailman.6128.1391085772.18130.python-list@python.org> <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com>
Date Fri, 31 Jan 2014 01:09:56 +1100
Subject Re: Add directory to sys.path based on variable
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6140.1391091007.18130.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391091008 news.xs4all.nl 2881 [2001:888:2000:d::a6]:38076
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65006

Show key headers only | 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