Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Python programs and relative imports Date: Sat, 9 Apr 2016 03:11:06 +1000 Lines: 23 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de IHUOCmNUtC/TZj6dyKuItQ4TfVAvHmj08rp5dFNFhHVA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'one?': 0.05; 'executable': 0.07; 'cc:addr:python-list': 0.09; 'imports': 0.09; 'semantics': 0.09; "they've": 0.09; 'syntax': 0.13; '2016': 0.16; 'accidental': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'rationale': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'script.': 0.18; 'load': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'prevent': 0.20; 'fairly': 0.22; 'explicit': 0.22; 'am,': 0.23; 'seems': 0.23; 'sat,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'oversight': 0.29; 'really,': 0.29; "i'm": 0.30; 'certainly': 0.30; 'relative': 0.30; 'anyone': 0.32; 'up.': 0.32; 'instead,': 0.33; 'received:google.com': 0.35; 'behind': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'why': 0.39; 'sure': 0.39; 'does': 0.39; 'some': 0.40; 'different': 0.63; 'obvious': 0.76; 'life.': 0.81; 'chrisa': 0.84; 'saying:': 0.84; 'working,': 0.84; 'to:none': 0.91 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; bh=MxqjIjr6HbI2tWtnETTs6lmrMH4ntHofpl81jRCSrV0=; b=XOcQd2kZDyH7qy1583auK0g3l7Ms6Y89/LkvRodR92dzh9angqplAXqTr4EjS5zGol r0nivf6oUdhp196S+laAhN5YLeRXxP/uvigXQ8r8B1BvA4juNUcvUDj8k6Fpg5ClI9ZA VEJKmWAlC5NGFImfzFGcT8uaFcK1LXvy8P/oEB+tN2pLDC1U6/Y/ALzaXT+r5IKfI3F6 nUtRLGlE/yKDCIYR1cPq9bf/b1tn38pSTFR2ZgposlF+EZ8RNWXBGeWfmXJWZcQzbJ9x cNtRzyMRDQ3cuNOMSMT6aKr+ZykAFmCLK2NLymPq9V5pEhdn3FQvppXkL0klPsTv95vK poRw== 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:date :message-id:subject:from:cc; bh=MxqjIjr6HbI2tWtnETTs6lmrMH4ntHofpl81jRCSrV0=; b=WZB73X1S4UL3unqsUehsT7sQbO1bHliq+rUXu6LO8o2gcSIzzRwHuzEXSLtAsfIP0E TFaegu4tN0knpTX+o17rc18uw/uP88OVFXONmuUTEaSyGDXP+FT6ZVR0k4MGngUNGdEA N0ivEaT2ePcvwI7bMZ0pfoV5RgBzpfIoUif6CZj0RSqiWbOLWkzEPWChjrlHAmeR6AWT qsrAlj0Fb+q7TtvSJWzksdTV+r6YQfcpTG3oQFgQSoTlWGl4WjA98SJiTWZX/JvFj51f CWQGDRIdemRDdI03eB8QeAm1O7TLl2Q4TF/OixpwtwhHt+Iiu9ycQImdqmuCW8DLlkhj TB5Q== X-Gm-Message-State: AD7BkJIke383l5rMgCo7t1Ar5UcFdfPwk0we8TwzSccIXBPkbPQDru7lxG+D7Qp0YGVDpMl/TlnWfuvY64P7MA== X-Received: by 10.107.169.32 with SMTP id s32mr9876795ioe.19.1460135466420; Fri, 08 Apr 2016 10:11:06 -0700 (PDT) In-Reply-To: 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: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:106694 On Sat, Apr 9, 2016 at 2:59 AM, Rob Gaddi wrote: > Rob Gaddi wrote: > >> Does anyone know the history of why relative imports are only available >> for packages and not for "programs"? It certainly complicates life. >> > > Really, no one? It seems like a fairly obvious thing to have included; > all of the reasons that you want to be explicit in saying: > > from . import mypkg > > in a package apply just as well in an executable script. But instead, > they've got different semantics such that you expressly _cannot_ use > relative imports in a script. This feels like such a glaring oversight > that there must have been some rationale behind it. You can use the simple "import mypkg" syntax to load these up. I'm not sure what you're looking for - do you want to prevent that syntax from working, to prevent accidental shadowing? ChrisA