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: 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: <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 Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, Feb 24, 2015 at 8:10 AM, Michael Torrie 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