my first python file is named "com1" and it has a code to increment the value of x and y for every 3 seconds the code is:
x=0
y=0
for i in range(500):
x = x 1
print (x)
y = y 1
print (y)
sleep(3)
my second code is named "com2" and i have used the following lines for the code:
from com1 import x
from com1 import y
z = x y
print(z)
this isnt printing z which is x y, but instead it is printing only the values of x and y Can anyone tell me how to modify so that in my second python file com2 i can get an output of z ?
CodePudding user response:
Hi check if this one satisfies your case
contents of comm1.py
import time
from comm2 import inc
obj = inc()
for i in range(500):
x,y = obj.increament()
print(x y)
time.sleep(3)
contents of comm2.py
class inc:
def __init__(self):
self.x = 0
self.y = 0
def increament(self):
self.x = self.x 1
self.y = self.y 1
return self.x,self.y