dimanche 29 juillet 2018

Passing Values One-Way between Python Scripts

I'm writing a program which involves the use of randomised numbers (r1, r2, r3), with these randomised numbers changing every 3 seconds for 1000 cycles.

I have a script that generates the randomised numbers (random.py), however I'm struggling in being able to have the other script (read.py) being able to access the values of r1, r2 and r3.

e.g. at time 't' r1 is generated by random.py = 56 and at the same time 't' read.py wants to access the value of r1.

As the values of r1, r2 and r3 change over time, read.py wants to be able to access whatever the 'current' value is.

I have tried importing random.py as a module but this executes random.py leading to the script being executed in its entirety (1000 cycles * 3secs) and doesn't achieve my goal.

random.py:

import time
import random

for i in range (1000):
  r1 = random.randinit(1,100)
  r2 = random.randinit(1,100)
  r3 = random.randinit(1,100)
  time.sleep(3)

Any help or advice greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire