Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103505
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Dan Stromberg <drsalists@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: "from module import data; print(data)" vs "import module; print(module.data)" |
| Date | Thu, 25 Feb 2016 08:20:59 -0800 |
| Lines | 42 |
| Message-ID | <mailman.129.1456417740.20994.python-list@python.org> (permalink) |
| References | <mailman.111.1456362461.20994.python-list@python.org> <56ce7762$0$11100$c3e8da3@news.astraweb.com> <CAGGBd_pkpMt8b8ybwLkS_E5K2dKNfTX__du5+w20EGF9c0TJrQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de YeyZnaIhSAUNzMNL2wBMOQhjvYKSz3leU4JXw1a2Z7sg== |
| Return-Path | <drsalists@gmail.com> |
| 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; 'see.': 0.07; 'cc:addr :python-list': 0.09; 'imports': 0.09; 'mutable': 0.09; 'subject:module': 0.09; 'wed,': 0.15; 'applies': 0.15; 'importing': 0.15; 'thu,': 0.15; '12:07,': 0.16; '2016': 0.16; '24,': 0.16; 'cases:': 0.16; 'cc:name:python list': 0.16; 'intuition': 0.16; 'opposite': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.16; 'thanks.': 0.18; '>>>': 0.20; '(not': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(a)': 0.22; 'affects': 0.22; 'class,': 0.22; 'am,': 0.23; 'feb': 0.23; 'import': 0.24; 'patch': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'compare': 0.27; 'message-id:@mail.gmail.com': 0.27; 'module.': 0.27; 'dan': 0.29; 'testing.': 0.29; 'regardless': 0.31; "can't": 0.32; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'instance': 0.35; 'unit': 0.35; 'there': 0.36; 'received:209.85': 0.36; 'modules': 0.36; 'pm,': 0.36; 'two': 0.37; 'say': 0.37; 'doing': 0.38; 'no,': 0.38; 'received:209': 0.38; '(1)': 0.38; 'anything': 0.38; 'shared': 0.38; 'data': 0.39; 'subject:from': 0.39; 'area': 0.39; 'received:209.85.214': 0.39; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'telling': 0.61; 'is.': 0.63; 'else.': 0.66; 'thursday': 0.66; 'subject': 0.70; 'accessed.': 0.84; 'surface': 0.84; 'subject:; ': 0.91; 'increases': 0.93 |
| 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:to :cc:content-type; bh=TmRN/2bV50YBgMA3EZCdthakdKXBJbmbcciEu+BukcU=; b=dcA7MFUFZL/XWa2WPH865XjIuVGrt2olmqx359HcjA86M0/vJOj7jHauvObcWtkWhb EYkhtla98GgzOsLuVr4u6TfD7ZGT8w1HJJdoE4H6vXlUvVdoT23leO3dryWI90VV8zC8 x0pWBoHt00slrHJadsI999dI90DA7HvDHSrJXQ/6NDa4Tz6DqQa68FWD3EMJjUjbISn3 TZ/zFn/gUtIXIabmQ3l8ALPfhbzMh2BjMM0QNjQsKddvzX1N0i8v/4bf/yBxmKIrAsyB uSEyC67Q05sae8VPR5b4dzWC7Dnr/2KWJwH/TqD9fp1wQRMXuNElMEbp8vhwTbwBMDDX 0WuA== |
| 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:to:cc:content-type; bh=TmRN/2bV50YBgMA3EZCdthakdKXBJbmbcciEu+BukcU=; b=jVxu+2Jduthf1pBCoDVx+BkX/vIhYbz3YAnRsQr1jbv43KNa3EeqNt2dgYH44y0Guw 83tRwR/A27HVMy30LsrEmaBgZofTbD/5SmmqjW/mO63PT7TGnrdR0FnlwEFp4nJNP1ea G+ebUioyjIIHwQX5oMdB2M898UW54jnXstDS62rud9BcD/Gmeb+wuFwcGd7TGrcsJyNf stoysfigpXGkevdeEwsC4gSsphmOesmrNExRO4RhbpNpnRcucpb1PZTpPamD4FKdqsBZ vT+16UEnWtrgCQlGwVR/0jmo/CRC4L6E/6RvccfUZH3ixMwLqkJoLdB3WVmePGwJDmSK GTqQ== |
| X-Gm-Message-State | AG10YOQ2B55SvzA7Kf8guG0bu2g0aoOhgqooYjqWtGVMYE9F1AYgwT8cqQefeGXZKPBFd0DVZF8je9hBepzrnA== |
| X-Received | by 10.182.55.10 with SMTP id n10mr37263661obp.68.1456417259395; Thu, 25 Feb 2016 08:20:59 -0800 (PST) |
| In-Reply-To | <CAGGBd_pkpMt8b8ybwLkS_E5K2dKNfTX__du5+w20EGF9c0TJrQ@mail.gmail.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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:103505 |
Show key headers only | View raw
On Thu, Feb 25, 2016 at 8:15 AM, Dan Stromberg <drsalists@gmail.com> wrote: > On Wed, Feb 24, 2016 at 7:39 PM, Steven D'Aprano > <steve+comp.lang.python@pearwood.info> 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) > >>> Is it fair to say that the former increases the surface area of your >>> shared (sometimes mutable) state? >> >> No, I can't say that it is. If anything, the opposite is the case: it >> decreases the surface area, because `data` now is local to the importing >> (not imported) module. Rebinding data will not affect anything else. > >> There are two scenarios (`from module import...` versus `import ...`), each >> with two cases: mutation, and rebinding: >> >> (1) from module import data >> >> (a) Mutation (only applies to mutable data like lists, dicts etc) >> >> In place mutation affects everything relying on module.data regardless of >> how or where it is accessed. > > We have some scenarios where "data" is an instance of a class, and we > need to monkey patch it for unit testing. > > Please ignore: My intuition is telling me that "module.data; data.mutate()" would be > easier to monkey patch in a way that all modules will see. Is that > fair to say? > > Thanks. Correction! 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?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
"from module import data; print(data)" vs "import module; print(module.data)" Dan Stromberg <drsalists@gmail.com> - 2016-02-24 17:07 -0800
Re: "from module import data; print(data)" vs "import module; print(module.data)" Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-02-25 14:39 +1100
Re: "from module import data; print(data)" vs "import module; print(module.data)" Dan Stromberg <drsalists@gmail.com> - 2016-02-25 08:15 -0800
Re: "from module import data; print(data)" vs "import module; print(module.data)" Dan Stromberg <drsalists@gmail.com> - 2016-02-25 08:20 -0800
Re: "from module import data; print(data)" vs "import module; print(module.data)" Ethan Furman <ethan@stoneleaf.us> - 2016-02-25 08:35 -0800
Re: "from module import data; print(data)" vs "import module; print(module.data)" Ethan Furman <ethan@stoneleaf.us> - 2016-02-25 08:51 -0800
Re: "from module import data; print(data)" vs "import module; print(module.data)" sohcahtoa82@gmail.com - 2016-02-25 12:00 -0800
Re: "from module import data; print(data)" vs "import module; print(module.data)" Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-02-26 11:20 +1300
Re: "from module import data; print(data)" vs "import module; print(module.data)" Ben Finney <ben+python@benfinney.id.au> - 2016-02-26 10:38 +1100
Re: "from module import data; print(data)" vs "import module; print(module.data)" Steven D'Aprano <steve@pearwood.info> - 2016-02-26 11:40 +1100
Re: "from module import data; print(data)" vs "import module; print(module.data)" Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-25 20:56 -0700
Re: "from module import data; print(data)" vs "import module; print(module.data)" Chris Angelico <rosuav@gmail.com> - 2016-02-26 15:11 +1100
Re: "from module import data; print(data)" vs "import module; print(module.data)" Ben Finney <ben+python@benfinney.id.au> - 2016-02-26 15:37 +1100
csiph-web