Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: A mistake which almost went me mad Date: Mon, 7 Mar 2016 09:19:15 -0700 Lines: 17 Message-ID: References: <56d81044$0$19756$426a74cc@news.free.fr> <20160303054822.342fb513@bigbox.christie.dr> <20160303125053.79e95bde@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de M9JSkuaAVKGXcu65FccXhgBb/XNGJZQPsEgt5vRLPHow== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'imports': 0.09; 'subject:which': 0.09; 'worked,': 0.09; 'importing': 0.15; 'packages.': 0.15; 'thu,': 0.15; '(and,': 0.16; '2016': 0.16; 'cwd': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'smtplib': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'first.': 0.18; 'prevent': 0.20; '2.x': 0.22; 'am,': 0.23; 'absolute': 0.23; 'import': 0.24; 'tim': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'another.': 0.29; 'chase': 0.29; 'crash': 0.29; 'finds': 0.29; "i'm": 0.30; 'relative': 0.30; "can't": 0.32; 'usually': 0.33; 'received:google.com': 0.35; 'path': 0.35; 'should': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'version': 0.38; 'received:209': 0.38; 'end': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'your': 0.60; 'mar': 0.65; 'forced': 0.84; 'to:name:python': 0.84; 'besides,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=pjztma9UGVV2B7AE510tA33T/ngqYzC+wz6z3YOsDBg=; b=wefT029zKWwmSZq6tFLzFV80oeBzLQHreL+1dQI3WOoqPdDZcCNm3XEiwW4eGbAY9r D3nCFCoIuzPSTylu/0luh6YA2JewH/jVizCge+qL/waA3Nsx0aP1wNEnSRmkT/+B9tTu 8JBHGFYL197T3Fd1g+rGzwn+dQ/0F3YAkqZ7oiJsUGpLoxV5HyreVgLWe19DtSYMxEG6 mAOpT7SyTZkgyDYBwh1L5nMVhdV/DjjNy3uKHgA2MnZhBUv1dLGdq1Q3mc5qBxuNg/cc OnQ389LsSGhgt17NOm1lib0i64q1U0g0U+O2YUFgcnWVa+2beqcrpOwNOxsARMs6Nx+Q 0nhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=pjztma9UGVV2B7AE510tA33T/ngqYzC+wz6z3YOsDBg=; b=ajP59Qkr/BeGg4rv3/98ejuBeEI5OQV32Op612DsLM3U2kSLw9ff0Otj6k9KvudnwN 90jxPLKui0Ay1zVzNoalyK+VCw4zafCOL+FWCSpRCHKF3VQnyh+xLHWyBiCXElABaWod Dxf6CiKmiSqt62Q0Bov0rTs7gb6jj9MTWClK7o0cMpZV1vIJ1fQj1hMWSfdSSyliViOr x6sC/yYu1ucciQ47aj1lCDY010kfijdJ6261hwkqPUp7D38gz9PTIJDuEr5Cyw6LUmIK CEc2Ogje0047JOgfqvjB85lQxO/8A8F6lhL7GRc3DbBgxA0Is1cd+ecf1zQAb5tOqrXQ LzDA== X-Gm-Message-State: AD7BkJKkZz/NnLRFEvYzk4NAahFZRN3crIZHLOn8SIE1AVjSC5Nkhv+sLjQ6XQi6soiQjf+LWJtws3ry0j+F8Q== X-Received: by 10.107.185.214 with SMTP id j205mr21985564iof.111.1457367595405; Mon, 07 Mar 2016 08:19:55 -0800 (PST) In-Reply-To: <20160303125053.79e95bde@bigbox.christie.dr> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104221 On Thu, Mar 3, 2016 at 11:50 AM, Tim Chase wrote: > I think that relative imports should ameliorate this, as I usually > hit it when I'm using smtplib which in turn imports "email" (and, in > 2.x when it found my local email.py would crash and burn). If it used > a relative import that forced it to find the one in the stdlib, it > should(?) prevent it from finding my local version first. Relative imports only work inside packages. You can't use a relative import to import one top-level module from another. Besides, the relative import doesn't help to disambiguate in this case. The absolute path of the stdlib email module is "email". The absolute path of the module in your CWD is also "email". Why should a relative import prefer one over the other? So I would think that even if it worked, it would still just end up importing the first one it finds on your sys.path.