Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Ben Finney
Steven D'Aprano writes: > On Fri, 26 Feb 2016 10:38 am, Ben Finney wrote: > > > Gregory Ewing writes: > > > >> sohcahto...@gmail.com wrote: > >> > Now, I've noticed people talking about importing os.path. Is there any > >> > reason to use "import os.path" rather than "import os"? Both of them

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Chris Angelico
On Fri, Feb 26, 2016 at 2:56 PM, Ian Kelly wrote: > 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

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Ian Kelly
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 > merel

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Steven D'Aprano
On Fri, 26 Feb 2016 10:38 am, Ben Finney wrote: > Gregory Ewing writes: > >> sohcahto...@gmail.com wrote: >> > Now, I've noticed people talking about importing os.path. Is there any >> > reason to use "import os.path" rather than "import os"? Both of them >> > will still put the "os" module in

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Ben Finney
Gregory Ewing writes: > sohcahto...@gmail.com wrote: > > Now, I've noticed people talking about importing os.path. Is there any > > reason to use "import os.path" rather than "import os"? Both of them will > > still put the "os" module into the global namespace. > > In the case of os.path it do

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Gregory Ewing
sohcahto...@gmail.com wrote: Now, I've noticed people talking about importing os.path. Is there any reason to use "import os.path" rather than "import os"? Both of them will still put the "os" module into the global namespace. In the case of os.path it doesn't matter, because the os module im

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread sohcahtoa82
On Wednesday, February 24, 2016 at 5:07:57 PM UTC-8, Dan Stromberg wrote: > Could people please compare and contrast the two ways of doing imports > in the Subject line? > > I've long favored the latter, but I'm working in a code base that > prefers the former. > > Is it fair to say that the form

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Ethan Furman
On 02/25/2016 08:20 AM, Dan Stromberg wrote: My intuition is telling me that "module.data; module.data.mutate()" would be easier to monkey patch in a way that all modules will see. Is that fair to say? It is fair to say that if you need to monkey-patch a module, you should import the module.

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Ethan Furman
On 02/24/2016 07:39 PM, Steven D'Aprano wrote: (2) import module (a) Mutation is no different from (1)(a) above. No change. (b) Rebinding `module.data = []` affects the imported module, and therefore everything that relies on it. More accurate: and therefore everything that has not already d

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Dan Stromberg
On Thu, Feb 25, 2016 at 8:15 AM, Dan Stromberg wrote: > On Wed, Feb 24, 2016 at 7:39 PM, Steven D'Aprano > wrote: >> On Thursday 25 February 2016 12:07, Dan Stromberg wrote: >> >>> Could people please compare and contrast the two ways of doing imports >>> in the Subject line? >> >> from module im

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Dan Stromberg
On Wed, Feb 24, 2016 at 7:39 PM, Steven D'Aprano wrote: > On Thursday 25 February 2016 12:07, Dan Stromberg wrote: > >> Could people please compare and contrast the two ways of doing imports >> in the Subject line? > > from module import data; print(data) > > import module; print(module.data) >>

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-24 Thread Steven D'Aprano
On Thursday 25 February 2016 12:07, Dan Stromberg wrote: > Could people please compare and contrast the two ways of doing imports > in the Subject line? from module import data; print(data) import module; print(module.data) > I've long favored the latter, but I'm working in a code base that >

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-24 Thread Cameron Simpson
On 24Feb2016 17:07, Dan Stromberg wrote: Could people please compare and contrast the two ways of doing imports in the Subject line? I've long favored the latter, but I'm working in a code base that prefers the former. I largely use the former "from module import name, name..." over "import

"from module import data; print(data)" vs "import module; print(module.data)"

2016-02-24 Thread Dan Stromberg
Could people please compare and contrast the two ways of doing imports in the Subject line? I've long favored the latter, but I'm working in a code base that prefers the former. Is it fair to say that the former increases the surface area of your shared (sometimes mutable) state? It's clear that