N00b question on Py modules

lokesh.jagasia at gmail.com lokesh.jagasia at gmail.com
Mon May 7 03:00:38 EDT 2007


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

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




More information about the Python-list mailing list