Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103507

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

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Ethan Furman <ethan@stoneleaf.us>
Newsgroups comp.lang.python
Subject Re: "from module import data; print(data)" vs "import module; print(module.data)"
Date Thu, 25 Feb 2016 08:51:39 -0800
Lines 15
Message-ID <mailman.131.1456419044.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> <CAGGBd_p5jd_4w-VhuGk+b3Swe926BYuNMaWKPN15PAEEzMkH_Q@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de LnakCl2wx9AiO9XaZzVZxQIbRCp678esbvv5rVAT9rpw==
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'see.': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'subject:module': 0.09; 'intuition': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; 'module,': 0.18; 'visible': 0.22; 'am,': 0.23; 'code.': 0.23; 'import': 0.24; 'patch': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'module.': 0.27; 'dan': 0.29; '~ethan~': 0.29; 'should': 0.36; 'modules': 0.36; 'to:addr:python- list': 0.36; 'say': 0.37; 'anything': 0.38; 'sure': 0.39; 'does': 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'telling': 0.61; 'charset:windows-1252': 0.62; 'subject:; ': 0.91
User-Agent Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
In-Reply-To <CAGGBd_p5jd_4w-VhuGk+b3Swe926BYuNMaWKPN15PAEEzMkH_Q@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:103507

Show key headers only | View raw


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.  :)

You should also import it before anything else does to make sure your 
change is visible to all other code.

--
~Ethan~

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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