FW: using globals
Hi,
I have got a problem with importing global variables. For instance I have got two files:
# t1.py #t2.py
counter = 1
def counter_adder(filenr): def show_adder(): global counter import t1 counter+= 1 print("adder is %d" % t1.counter) if filenr == 1: show_adder() else: import t2 t2.show_adder()
def show_adder(): print("adder is %d" % counter)
counter_adder(1) adder is 2 counter_adder(2) adder is 1
When I look at the outcome of two function calls I expected no differences but much to my surprise it goes wrong when the global variable is imported. It doesn't give the updated value but the value it get when instantiated. Who come? What should I do to get the updated value
greetings,
Sjaak van Werkhoven
****************************DISCLAIMER*********************************** Deze e-mail is uitsluitend bestemd voor de geadresseerde(n). Verstrekking aan en gebruik door anderen is niet toegestaan. Fortis sluit iedere aansprakelijkheid uit die voortvloeit uit electronische verzending. This e-mail is intended exclusively for the addressee(s), and may not be passed on to, or made available for use by any person other than the addressee(s). Fortis rules out any and every liability resulting from any electronic transmission. ******************************************************************************
On Wednesday, August 02, 2006, at 01:02PM, Werkhoven J.P. van (Sjaak)
Hi,
I have got a problem with importing global variables. For instance I have got two files:
Your message is off-topic for python-dev, this list is for the development OF python, not development WITH python. You're much likier to get an answer on python-list or comp.lang.python (which are the same). BTW. The formatting of the source-code in you're e-mail was such that I have no idea how it is supposed to look :-( Regards, Ronald
participants (2)
-
Ronald Oussoren
-
Werkhoven J.P. van (Sjaak)