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


Groups > comp.lang.python > #52689

Re: Importing variables non-deterministic?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'importing': 0.05; 'interpreter': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'bug': 0.12; "wouldn't": 0.14; 'behave': 0.16; 'bug,': 0.16; 'bypassed': 0.16; 'cares': 0.16; 'protecting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:non': 0.16; 'subsequently': 0.16; 'exception': 0.16; 'language': 0.16; 'wrote:': 0.18; 'library': 0.18; 'variable': 0.18; 'mechanism': 0.19; 'value.': 0.19; 'code,': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'least': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'character': 0.29; "doesn't": 0.30; 'statement': 0.30; 'code': 0.31; 'that.': 0.31; 'clever': 0.31; 'constant': 0.31; 'initialized': 0.31; 'view.': 0.31; "we're": 0.32; "can't": 0.35; 'case,': 0.35; 'definition': 0.35; 'subject:skip:d 10': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'changing': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'that,': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'most': 0.60; 'free': 0.61; 'reserved': 0.61; 'name': 0.63; 'places': 0.64; 'provide': 0.64; 'total': 0.65; 'safe': 0.72; 'protect': 0.79; 'idiot': 0.84; 'pardon': 0.84; 'partially': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Importing variables non-deterministic?
Date Mon, 19 Aug 2013 12:33:32 +0000 (UTC)
References <a75383ec-b363-4ad4-9703-ca5d8ea614df@googlegroups.com> <520f9054$0$30000$c3e8da3$5496439d@news.astraweb.com> <5211C5BD.5040209@rece.vub.ac.be> <kusidq$kaa$1@ger.gmane.org> <5211D464.5090303@rece.vub.ac.be> <CAPTjJmqvzkuZ8Pmux=K6SSPBeLuDQiD99t7g_pAwujCfb2ON4g@mail.gmail.com> <5211DF6C.6030603@rece.vub.ac.be> <CAPTjJmoATrm+Ke5LNu3zJ-2YppBDqOSTXRP+USwNWrpH64r0sQ@mail.gmail.com> <52120783.8040008@rece.vub.ac.be>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 174.32.174.30
User-Agent XPN/1.2.6 (Street Spirit ; Linux)
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 <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.28.1376915632.19984.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376915632 news.xs4all.nl 15920 [2001:888:2000:d::a6]:49874
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52689

Show key headers only | View raw


Antoon Pardon wrote:

> Op 19-08-13 11:18, Chris Angelico schreef:
    <snip>
>> The issue
>> was regarding imports, and it's perfectly safe to import a constant,
>> even if the interpreter doesn't protect you from then being a total
>> idiot and changing it.
>
> Python doesn't have constants, so you statement about importing a
> constant doesn't make sense. The point is that python doesn't provide
> the mechanism for protecting names against reassignments. So you
> don't know whether the variable you think of as a constant is so
> in reality. And this from a pure language definition point of view.
> That you can use tools that make the interpreter no longer behave
> as the language should, doesn't negate that.
>

Who cares what the language "protects?"  I don't know any language
whose protections can't be at least partially bypassed by clever
foot-shooters.  In any case, we all know that Python doesn't protect
constants, so we're free to use the word in a friendlier way.

A Python constant is what I use as a constant.  I follow Pep-8 and make
it all caps.  So in any library I write struct_global.y  would be a bug
or a design flaw.  (And with a single character name like that, it
wouldn't be global in any case.  Single character names are reserved
for play code and for short loops)

And if I subsequently change it in my calling code, it isn't a
constant any more.  If I rebind the name, it's not even the same
variable any more.

That's a bug, not an exception to the rule "don't use global variables."

I also accept as a constant those values which are initialized
sufficiently early in the code that most places will only ever see the
final value.  Those may be global without worry.

-- 
DaveA

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


Thread

Importing variables non-deterministic? tmellman@googlemail.com - 2013-08-17 07:25 -0700
  Re: Importing variables non-deterministic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-17 15:01 +0000
    Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 09:14 +0200
    Re: Importing variables non-deterministic? Dave Angel <davea@davea.name> - 2013-08-19 07:45 +0000
    Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 10:16 +0200
      Re: Importing variables non-deterministic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-19 16:57 +0000
        Re: Importing variables non-deterministic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-19 17:16 +0000
          Re: Importing variables non-deterministic? Chris Angelico <rosuav@gmail.com> - 2013-08-19 18:25 +0100
        Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 19:40 +0200
    Re: Importing variables non-deterministic? Chris Angelico <rosuav@gmail.com> - 2013-08-19 09:32 +0100
      Re: Importing variables non-deterministic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-19 17:05 +0000
        Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 22:34 +0200
          Re: Importing variables non-deterministic? Steven D'Aprano <steve@pearwood.info> - 2013-08-20 05:48 +0000
            Re: Importing variables non-deterministic? wxjmfauth@gmail.com - 2013-08-19 23:40 -0700
            Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-20 08:55 +0200
              Re: Importing variables non-deterministic? wxjmfauth@gmail.com - 2013-08-20 00:31 -0700
                Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-20 09:55 +0200
                Re: Importing variables non-deterministic? wxjmfauth@gmail.com - 2013-08-20 02:15 -0700
    Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 11:03 +0200
    Re: Importing variables non-deterministic? Chris Angelico <rosuav@gmail.com> - 2013-08-19 10:18 +0100
    Re: Importing variables non-deterministic? Peter Otten <__peter__@web.de> - 2013-08-19 11:49 +0200
    Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 13:54 +0200
    Re: Importing variables non-deterministic? Dave Angel <davea@davea.name> - 2013-08-19 12:33 +0000
    Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 16:55 +0200
    Re: Importing variables non-deterministic? Chris Angelico <rosuav@gmail.com> - 2013-08-19 16:04 +0100
    Re: Importing variables non-deterministic? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-19 19:25 +0200
    Re: Importing variables non-deterministic? Ben Finney <ben+python@benfinney.id.au> - 2013-08-20 11:14 +1000

csiph-web