Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'importing': 0.05; '(except': 0.07; 'class,': 0.07; 'sys': 0.07; 'assigning': 0.09; 'constructor': 0.09; 'latter': 0.09; 'methods,': 0.09; 'subject:modules': 0.09; 'typed': 0.09; 'used.': 0.09; 'python': 0.11; 'assume': 0.14; 'assignments': 0.16; 'chris,': 0.16; 'coupling': 0.16; 'easier.': 0.16; 'globals': 0.16; 'instantiated': 0.16; 'recipe': 0.16; 'singleton': 0.16; 'stdout': 0.16; 'subject:variable': 0.16; 'sys.stdout': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'module': 0.19; 'later': 0.20; '(the': 0.22; 'import': 0.22; 'cc:addr:gmail.com': 0.22; 'to:name:python-list@python.org': 0.22; 'preferences': 0.24; 'test.': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'possibly': 0.26; 'defined': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'thus': 0.29; 'url:mailman': 0.30; 'easier': 0.31; "skip:' 10": 0.31; 'constant': 0.31; 'convenience': 0.31; 'sep': 0.31; 'file': 0.32; 'url:python': 0.33; '(e.g.': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'accessing': 0.36; 'url:listinfo': 0.36; 'useful': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'throughout': 0.37; 'wrong': 0.37; 'being': 0.38; 'initially': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'enough': 0.39; 'called': 0.40; 'users': 0.40; 'url:mail': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'easy': 0.60; 'john': 0.61; 'strictly': 0.61; 'simple': 0.61; 'header:Message-Id:1': 0.63; 'needing': 0.65; 'here': 0.66; 'between': 0.67; 'hand': 0.80; '2013,': 0.91; 'destination': 0.91; 'whereas': 0.91 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: global variable across modules From: John Pote In-Reply-To: <9B9863FC-086A-4A0B-87BF-8F4AD070C90E@o2.co.uk> Date: Thu, 12 Sep 2013 01:10:07 +0100 Content-Transfer-Encoding: quoted-printable References: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> <9B9863FC-086A-4A0B-87BF-8F4AD070C90E@o2.co.uk> To: "python-list@python.org" X-Mailer: Apple Mail (2.1508) 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: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378944677 news.xs4all.nl 15879 [2001:888:2000:d::a6]:34737 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54013 Sorry about the html - did not realise. Thanks for your comments. John On 11 Sep 2013, at 22:49, John Pote wrote: > Chris, > Interesting.=20 >>=20 >> # Test1.py >> Debug_Value =3D " " >>=20 >> # Test2.py >> from Test1 import * >> # is exactly equivalent to >> Debug_Value =3D " " >>=20 > I take it then that assigning to Debug_Value in Test2.py will not = change the value of Debug_Value in Test1.py. >=20 > That being the case it would be wrong to assume that the following are = identical >=20 > import sys >=20 > and >=20 > from sys import * >=20 > (the latter being a convenience to avoid having to write sys. before = every variable). >=20 > Thus assigning to sys.stdout would change the standard out destination = in every module importing sys whereas >=20 > from sys import * > stdout =3D foo.dst >=20 > would only change stdout in the current module and sys.stdout would = remain unchanged. >=20 > Is my understanding here correct? >=20 > As to global usage I do find it useful to have a file called something = like 'preferences.py' and put in there constants to be used throughout = the application. But I use these strictly read only. It is good in that = system wide constants are defined in one place only. Also if the = constants are put inside a class, possibly with getter methods, = instantiated as a singleton then initially the values can be typed = directly into the preferences file. Later the constructor could be = changed to read the constants from an initialisation file of your own = format (e.g. .ini or JSON). Thus users without python experience might = find it easier to change them without having to look at any python code. = On the other hand I appreciate simple constant assignments should be = easy enough to change without needing to know any Python. >=20 > Also remember that accessing any form of global that is shared between = multiple threads is a recipe for disaster unless appropriate locks are = used. A significant advantage of not using globals (except for system = wide constants) is that is makes testing of individual modules easier. = The less coupling there is between modules the easier it is to = understand and test. >=20 > Regards all, > John > --=20 > https://mail.python.org/mailman/listinfo/python-list