global vars across modules
Thomas 'PointedEars' Lahn
PointedEars at web.de
Wed Apr 25 04:13:49 EDT 2012
John Nagle wrote:
> On 4/22/2012 12:39 PM, mamboknave at gmail.com wrote:
>> Question:
>> How can I access to the global 'a' in file_2 without resorting to the
>> whole name 'file_1.a' ?
>
> Actually, it's better to use the fully qualified name "file_1.a".
> Using "import *" brings in everything in the other module, which often
> results in a name clash.
>
> Just do
>
> import file_1
>
> and, if desired
>
> localnamefora = file_1.a
I think it is better to write
from file_1 import a as localnamefora
instead, unless `localnamefora' should be the identifier of a
(function-)local variable.
<http://docs.python.org/release/2.7.3/reference/simple_stmts.html#the-
import-statement>
<http://docs.python.org/py3k/reference/simple_stmts.html#the-import-
statement>
--
PointedEars
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
More information about the Python-list
mailing list