N00b question on Py modules

rishi pathak mailmaverick666 at gmail.com
Mon May 7 03:14:32 EDT 2007


Hi
this  variable is local to function
do this
def setExitCode():
   global _exitcode
   _exitcode = 1
On 7 May 2007 00:00:38 -0700, lokesh.jagasia at gmail.com <
lokesh.jagasia at gmail.com> wrote:
>
> Hi. Sorry to sound like a noob but that's what I am when it comes to
> Python. I just wrote the below module and it behaves funny.
>
> My python module:
>
> _exitcode = 0
>
> def setExitCode():
>     _exitcode = 1


this  variable is local to function

if __name__ == '__main__':
>     print _exitcode
>     setExitCode()
>     print _exitcode
>
> Actual O/P:
> 0
> 0
>
> I expected to see an output of 0 followed by 1. But it turns out that
> the _exitcode variable is not changed at all. It seems that
> setExitCode() might be editing a local copy of the _exitcode variable.
> But then, how do I tell it to change the value of the module variable
> and not its local variable.
>
> I've been through the modules section of Python docs and a few ebooks
> as well, all suggest that it shouldn't be working this way.
>
> Please help out ppl.
>
> Thanks
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070507/cd662320/attachment.html>


More information about the Python-list mailing list