<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6617.93">
<TITLE>namespace question</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">Hi all,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">I'm confused by namespaces in python, specifically using the global keyword. I'm able to access and modify a global variable from a function if the function is defined in the same module but not if the function is defined in a different module:</FONT></P>
<P><FONT SIZE=2 FACE="Courier New">//File t2.py</FONT>
<BR><FONT SIZE=2 FACE="Courier New">def sn():</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> global test_var </FONT>
<BR><FONT SIZE=2 FACE="Courier New"> test_var = 2</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">//File t1.py</FONT>
<BR><FONT SIZE=2 FACE="Courier New">test_var = 1</FONT>
<BR><FONT SIZE=2 FACE="Courier New">print test_var</FONT>
<BR><FONT SIZE=2 FACE="Courier New">from t2 import sn</FONT>
<BR><FONT SIZE=2 FACE="Courier New">sn()</FONT>
<BR><FONT SIZE=2 FACE="Courier New">print test_var</FONT>
<BR><FONT SIZE=2 FACE="Courier New">def so():</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> global test_var </FONT>
<BR><FONT SIZE=2 FACE="Courier New"> test_var = 3</FONT>
<BR><FONT SIZE=2 FACE="Courier New">so()</FONT>
<BR><FONT SIZE=2 FACE="Courier New">print test_var</FONT>
</P>
<BR>
<P><FONT SIZE=2 FACE="Arial">The output from running t1 is:</FONT>
<BR><FONT SIZE=2 FACE="Arial">1</FONT>
<BR><FONT SIZE=2 FACE="Arial">1</FONT>
<BR><FONT SIZE=2 FACE="Arial">3</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Can anyone tell me how I can modify the test_var variable form another module?</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Pete</FONT>
</P>
</BODY>
</HTML>