Hi,
I am having some difficulties to use global statement.
I have written two scripts : the first contains a def statement which
defines a function "test" and variables "a, b, c". In the second script,
I would like to print "a" , allocate a value to "b" and print "c".
first script : script_test
def test():
a = 3
c = a + b
main script : main_script_test
import script_test
script_test.test()
print a
b = 5
print c
Is it possible to do this by using a global statement to define the
variables?
I have already tried but in vain.
Can you tell me if this method is good or not? Or can you give me
another method?
Thanks for your help
Graziella
···
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users
How about this:
#script_test.py:
a = 0
b = 0
c = 0
def test():
global a,b,c
a = 3
c = a + b
···
At 05:54 AM 12/14/2000, you wrote:
Hi,
I am having some difficulties to use global statement.
I have written two scripts : the first contains a def statement which
defines a function "test" and variables "a, b, c". In the second script,
I would like to print "a" , allocate a value to "b" and print "c".
first script : script_test
def test():
a = 3
c = a + b
main script : main_script_test
import script_test
script_test.test()
print a
b = 5
print c
--------------
#main.py
import script_test
script_test.test()
print script_test.a
script_test.b = 5
print script_test.c
script_test.test()
print script_test.c
Is it possible to do this by using a global statement to define the
variables?
So yes, it is, but you forgot that those global variables are global to the script_test module.
-greg
----
greg Landrum (greglandrum@earthlink.net)
Software Carpenter/Computational Chemist
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users
also, best to limit use of globals when you can get away with simply using a
variable local to the function as the globals will stay in (and consume)
memory.... sometimes, there's no other way though.
-S
···
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users