Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with variables between files loozing value

Status
Not open for further replies.

Impaled

Programmer
Apr 11, 2005
6
0
0
US
Ok so I have a new problem, and I cannot figure out how to fix it. I think I have tried pretty much everythign I can think of so I'm here to ask another newbie question.

If I have 3 simple files:

--data.py-----------
que = 0;
--------------------

--func.py--------------------
from data import *;

def addq():

global que;
que = que + 1;
print que;
------------------------------

--main.py--
from data import *;
from func import *;


que = que + 1;

print que;
addq();
addq();
--------------------------

When i ran "python main.py" I figured the output would be:

1
2
3

But instead it was:

1
1
2

So they are not accessing the same variable que. How do I make them all affect the same variable? Anyone know? Any reply is greatly appreciated.

 
To answer my own question in case anyone was wondering I had to create a class within data.py like this:

class data:
que =0;

q = data;

then I would just:

from data import *;

and acces q.que instead :)

So no need to reply I think I have it figured out ;)
 
I think you would have had similar success if you imported the namespace, i.e.:
Code:
import data

data.q = 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top