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: 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> <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 Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Fri, Jan 31, 2014 at 1:03 AM, loial 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