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

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.029
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; '#include': 0.09; 'exist,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"import"': 0.16; '24,': 0.16; 'behavior:': 0.16; 'does,': 0.16; 'fetch': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:between': 0.16; 'subject:object': 0.16; 'wrote:': 0.18; 'module': 0.19; 'feb': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'module,': 0.24; 'tells': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'michael': 0.29; 'feature': 0.29; 'am,': 0.29; 'quickly': 0.29; "doesn't": 0.30; '(like': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; 'though.': 0.31; 'file': 0.32; 'run': 0.32; 'up.': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'module.': 0.36; 'pm,': 0.38; 'expect': 0.39; 'how': 0.40; 'access,': 0.60; 'up,': 0.60; 'course': 0.61; 'simple': 0.61; 'email addr:gmail.com': 0.63; 'grab': 0.64; 'hang': 0.67; 'behavior': 0.77; '2015': 0.84; 'it"': 0.84; 'subject:Best': 0.91; 'to:none': 0.92
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:cc :content-type; bh=94vy98LsnvqDWwz4MRHRXQQ/sS9ihv/H9fYFPW1zi2M=; b=BwMn+fx/t1qj5j0vhoz6zD2HwkBI/jzgShdJt1qPwoFDCLh2/EHqUlmRqaLT98QffO pFzCTbE1DuLgoRpc1j6C4PUnK9cxNPuWQgtGa+XHDY66/vuYM0TeSwM6/6AMfXKMNNO+ d8Knk0d4eTplcY13P/ME5u4wKQgccXD7a2ZUrSDoVusQtkSjEpanmB43lIr9mMfNYaxa D3v9A3iES2Q30WZmzeLtr0ioJ8dUkGmeCg/3VSQrrhBTYmP48ijg3d8S4eCQdGkCkbi8 YQfqUWdk66fIgigTNR3lLQTRB61VDtVP+IOAPFyVdRo5W/F34xiDNwloRn21FbdWaGkr WeHA==
MIME-Version 1.0
X-Received by 10.107.160.212 with SMTP id j203mr17489343ioe.43.1424736897551; Mon, 23 Feb 2015 16:14:57 -0800 (PST)
In-Reply-To <54EB972F.1040102@gmail.com>
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 Tue, 24 Feb 2015 11:14:57 +1100
Subject Re: Best practice: Sharing object between different objects
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.19108.1424736906.18130.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424736906 news.xs4all.nl 2930 [2001:888:2000:d::a6]:36072
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86278

Show key headers only | 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