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


Groups > comp.lang.python > #86278

Re: Best practice: Sharing object between different objects

References <aacac55a-6779-4ad3-96f4-5332ff36a365@googlegroups.com> <mcfqeb$5tb$1@dont-email.me> <mailman.19095.1424717125.18130.python-list@python.org> <ac52606e-f85f-4e94-8dac-6556e28821be@googlegroups.com> <54EB972F.1040102@gmail.com>
Date 2015-02-24 11:14 +1100
Subject Re: Best practice: Sharing object between different objects
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.19108.1424736906.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Feb 24, 2015 at 8:10 AM, Michael Torrie <torriem@gmail.com> wrote:
> On 02/23/2015 01:02 PM, sohcahtoa82@gmail.com wrote:
>> That behavior always trips me up.  My intuition tells me that every
>> time you import a module, it re-runs the code in the module.  So if I
>> had a simple module named myModule.py that had a single line with
>> `myInt = 1`, then I would *EXPECT* this behavior:
>
> I can see how coming from PHP would trip you up, though.  Of course I
> never got the hang of include vs include_once vs require vs require_once.

If you think of "import" as "go and grab this file of code and run it"
(like PHP's include or a preprocessor #include directive), then yes,
you would expect that. But think of it, instead, as "give me access to
this feature". If that feature doesn't yet exist, Python will go and
fetch it up; but if it does, yay! You now have access, really quickly
and easily.

ChrisA

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


Thread

Best practice: Sharing object between different objects pfranken85@gmail.com - 2015-02-21 04:15 -0800
  Re: Best practice: Sharing object between different objects Dave Angel <davea@davea.name> - 2015-02-21 09:28 -0500
  Re: Best practice: Sharing object between different objects Paul Rubin <no.email@nospam.invalid> - 2015-02-21 09:18 -0800
  Re: Best practice: Sharing object between different objects Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-02-23 18:10 +0000
    Re: Best practice: Sharing object between different objects Michael Torrie <torriem@gmail.com> - 2015-02-23 11:36 -0700
      Re: Best practice: Sharing object between different objects sohcahtoa82@gmail.com - 2015-02-23 12:02 -0800
        Re: Best practice: Sharing object between different objects Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-23 20:13 +0000
        Re: Best practice: Sharing object between different objects Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-23 13:39 -0700
        Re: Best practice: Sharing object between different objects Michael Torrie <torriem@gmail.com> - 2015-02-23 14:10 -0700
        Re: Best practice: Sharing object between different objects Chris Angelico <rosuav@gmail.com> - 2015-02-24 11:14 +1100

csiph-web