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


Groups > comp.lang.python > #4582

Re: Why do directly imported variables behave differently than those attached to imported module?

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 <chris@rebertia.com>
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 <BANLkTik1bNumywuwMiQHPS6kTsf7ig+3Pw@mail.gmail.com>
References <d8d1d20e-2edd-49e5-917c-f338ef35006f@l18g2000yql.googlegroups.com> <BANLkTikT3qeeMAToUhO7GDrve5fAJ_+vFg@mail.gmail.com> <BANLkTik1bNumywuwMiQHPS6kTsf7ig+3Pw@mail.gmail.com>
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 <clp2@rebertia.com>
To Chris Angelico <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1129.1304460710.9059.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Tue, May 3, 2011 at 2:47 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Wed, May 4, 2011 at 2:57 AM, Chris Rebert <clp2@rebertia.com> 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

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


Thread

Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 09:31 -0700
  Re: Why do directly imported variables behave differently than those attached to imported module? Chris Rebert <clp2@rebertia.com> - 2011-05-03 09:57 -0700
  Re: Why do directly imported variables behave differently than those attached to imported module? Daniel Kluev <dan.kluev@gmail.com> - 2011-05-04 03:57 +1100
  Re: Why do directly imported variables behave differently than those attached to imported module? Mel <mwilson@the-wire.com> - 2011-05-03 13:00 -0400
  Re: Why do directly imported variables behave differently than those attached to imported module? Terry Reedy <tjreedy@udel.edu> - 2011-05-03 13:13 -0400
  Re: Why do directly imported variables behave differently than those attached to imported module? harrismh777 <harrismh777@charter.net> - 2011-05-03 12:24 -0500
    Re: Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 11:51 -0700
      Re: Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 12:23 -0700
        Re: Why do directly imported variables behave differently than those attached to imported module? Daniel Kluev <dan.kluev@gmail.com> - 2011-05-04 06:55 +1100
  Re: Why do directly imported variables behave differently than those attached to imported module? Chris Angelico <rosuav@gmail.com> - 2011-05-04 07:47 +1000
    Re: Why do directly imported variables behave differently than those attached to imported module? Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-04 08:44 +0000
  Re: Why do directly imported variables behave differently than those attached to imported module? Chris Rebert <clp2@rebertia.com> - 2011-05-03 15:11 -0700

csiph-web