Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:module': 0.04; 'wed,': 0.04; 'foo': 0.09; 'pm,': 0.11; 'essentially': 0.12; 'am,': 0.14; 'wrote:': 0.14; 'doing:': 0.16; 'guessing': 0.16; 'rebert': 0.16; 'subject:directly': 0.16; 'subject:those': 0.16; 'tue,': 0.20; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'cheers,': 0.20; '(or': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'module,': 0.23; 'objects': 0.24; 'received:209.85.220': 0.26; 'instead': 0.26; 'classes': 0.26; 'chris': 0.27; 'function': 0.27; 'message-id:@mail.gmail.com': 0.28; 'load': 0.28; 'subject:?': 0.29; 'class': 0.29; 'sort': 0.30; 'least': 0.30; 'seem': 0.30; 'cc:addr:python.org': 0.31; 'import': 0.32; 'bit': 0.33; 'module': 0.33; 'reference': 0.34; 'using': 0.34; 'it?': 0.37; 'received:209.85': 0.37; '(by': 0.38; 'received:google.com': 0.38; 'though': 0.38; 'hold': 0.39; 'not,': 0.39; 'set': 0.39; 'skip:s 30': 0.39; 'received:209': 0.39; 'would': 0.40; 'header:Received:5': 0.40; 'exact': 0.60; '2011': 0.62; 'var': 0.65; 'subject:Why': 0.84; 'virtue': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=mBkgVBsxpa06rhPmzeitGxogYmot9FY2SKnJVReYMTU=; b=eY66TghWjAyDpKfJK5fnIVX0AApoaHPwLSd+QmGe6W6ISTNL08kRjX9i/UOuBiv/Ky lgXfPtXFbgzRpxTmuvWcyPlJ0OIiC0PIzJjpaVQwVLTbIxmYC8WKKeWwwNqRaXoUoQEh 8SRy/F7s/fpe9oDhb+gfHw+l5vJ47sBtkrHHE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=NSIHo/xPvXvo5N8yHC+GA2IA4t5B4BSiHrR5qzYQvsGARYE4hdnjaHAi7Xq811DVHb 7/9Tqh/wG0DZOXS82RAaCWp7nEyiD6/rHTR47U66T6GyYaByk/jjDKjY7jx3TCseQY/O za4+KTHs7Ak9nwXW3ouV6cot2HdFVH3IMfjeQ= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Tue, 3 May 2011 15:11:48 -0700 X-Google-Sender-Auth: nNwc7oyA_VJw5W3-2vmPIobGSNY Subject: Re: Why do directly imported variables behave differently than those attached to imported module? From: Chris Rebert To: Chris Angelico Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 29 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304460711 news.xs4all.nl 34849 [::ffff:82.94.164.166]:39314 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4582 On Tue, May 3, 2011 at 2:47 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 2:57 AM, Chris Rebert wrote: >> from foo import * >> >> can be thought of as essentially doing: >> >> import foo >> set = foo.set >> var = foo.var >> del foo > > Here's a side point. What types will hold a reference to the enclosing > module (or at least its dictionary)? Would it be possible to use a > from import to load a module, then "lose" the module even though > you're using objects from it? > > I am guessing that a function or class will hold such a reference, > because otherwise it would be a bit awkward for them to use any sort > of module-level state. Or do they not, and instead go look for their > module in sys.modules? some_python_function.__globals__ is the exact reference you postulated. Classes don't seem to hold such references; their methods do though (by virtue of being function objects), which makes sense. Cheers, Chris -- http://rebertia.com