Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: "from module import data; print(data)" vs "import module; print(module.data)" Date: Thu, 25 Feb 2016 20:56:18 -0700 Lines: 35 Message-ID: References: <535b56b5-f836-4cd6-ae95-33f18004c90b@googlegroups.com> <56cf9f01$0$1620$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de dVIrE2a6vlnEuu5lfKPV+A1sdbx1QHolyR5xxuIcg3mw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; '(especially': 0.07; 'collections': 0.09; 'concurrent': 0.09; 'modules.': 0.09; 'os.path': 0.09; 'special,': 0.09; 'subject:module': 0.09; 'python': 0.10; 'suggest': 0.15; 'thu,': 0.15; '2016': 0.16; 'namespace.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'attribute': 0.18; 'documented': 0.18; "aren't": 0.22; 'os,': 0.22; 'feb': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'module': 0.25; "doesn't": 0.26; 'skip:" 20': 0.26; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'module.': 0.27; 'publicly': 0.29; 'another': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'done': 0.35; 'path': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'cases': 0.36; "wasn't": 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'two': 0.37; 'being': 0.37; 'things': 0.38; 'received:209': 0.38; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'different': 0.63; 'between': 0.65; 'detail.': 0.66; 'special': 0.73; 'analog': 0.84; 'demonstrates': 0.84; 'to:name:python': 0.84; 'seriously,': 0.91; 'subject:; ': 0.91; 'besides,': 0.93; 'package:': 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=YLNQps+W9gBqx7BB/sTNvB3XKyoecoTj2YHWUMBE3zY=; b=UbbhEnGULGscgu2JZCTimu2mNN/lWms6w69JRF8qq6HD7LqEzNeuEe4Ni3EWIWHKB6 66SwmOfQJUVkP8ogVKcuw7DKuDfr2c0jYpy1evEj4hWv7OGPSPUeP+Zbvd8S2D1eA96b 84wTTyQ8swnB4IWqiZTFoAA7EV4Ac6QiS930Mf3fmP3VIppn108o/VMPXMSneRE6C9d6 zrotgN83tXTg/F/HT01neJLHBuP/lciUFrV9HwZ/hJUDluGZXlrschSYkWB72gfJ9Amo tpDCKq+kphWiEdEQdGMUHLNNJtNA0vT4raIeNnnQlSs12yoeVAVho6iLBcrESBGdey6u RPnQ== 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=YLNQps+W9gBqx7BB/sTNvB3XKyoecoTj2YHWUMBE3zY=; b=Yxxcxj5Z9zBUz6J0OZ4HidUbQfZLSocXRBwQFk3HxlmpGEDcBAuBW4TqfMbKxjl9B7 /E9CRixN+IbHqG/BqFWR4/3VIEWWKN4UXpM9s4CTEbvhZ5ILtI715wrfLp4hgB6L6Hc7 ynO06016VGhxmIo+aGcNLJTzEQjvABSuIoHqEhUepgj3aJ9MRoygLhZKyTeSvsoTmwlv eTO8K+va9J0CsefzODgW034yFtT0uUrZstRTohp8tkLcbWF9vEmHF45O27RNEquKZyvV PsnsUPCCRhu1v0yYQwgWrOYQ4QlumWRRC10npPgP7/bOU4I8BdbWnshzc/jo1iyiaOsG uDaw== X-Gm-Message-State: AG10YOQ7Q+SHy8Ume2wk9O8W0Jmae+Pne8vgusrejnqjt/5oCgJ/JL7AQAVpVHkUFoUKfIzDEatjgMG1Rq/sCw== X-Received: by 10.107.11.93 with SMTP id v90mr6294188ioi.188.1456459017956; Thu, 25 Feb 2016 19:56:57 -0800 (PST) In-Reply-To: <56cf9f01$0$1620$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 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:103525 On Thu, Feb 25, 2016 at 5:40 PM, Steven D'Aprano wrote: > If you take "Special cases are not special enough" seriously, you will not > use `import os.path` since os is not a package: > > py> os.__package__ > '' > > and os.path is not part of os, it's just a publicly exposed attribute which > merely happens to be a module. Being a module doesn't make it special, it's > just another name in the os namespace. I trust that you wouldn't insist on > writing: > > import os.listdir > > (especially since that doesn't work). Neither should you insist on writing > `import os.path`, since path is documented as a public part of the os > module. It has done so since at least Python 1.5. I disagree. The fact that os is not a package is an implementation detail. I for one wasn't even aware of it prior to reading your post. The name of the concurrent.futures module is "concurrent.futures". If you want to use it, you import concurrent.futures, not concurrent. Likewise, the name of the os.path module is "os.path". If you want to use it, you import os.path, not os. The fact that concurrent and os are two different types of things is irrelevant. Besides, packages *are* modules. To take another example, collections is a package (I checked), and collections.abc is a module. But collections also contains things that aren't modules. If you want to use collections.abc, you have to import it, but at the same time you don't import collections.Counter. This demonstrates that the analog you suggest between os.path and os.listdir is flawed.