My question is: i have a flask server which receives data and another python script which use that data everytime they change.
More precisely I have a class where the data is set by Flask and then the other script uses getters to get the new data.
I tried to share the same class instance across the two file but it doesn't work.
Flask app (app.py):
from user import Usert
# ...
user = User()
@app.route('/', methods=["GET", "POST"])
@app.route('/index', methods=["GET", "POST"])
def index():
if request.method == "POST":
data = request.get_json()
s1 = json.dumps(data)
d2 = json.loads(s1)
if("something" in d2):
user.set_something = #new value received
# other things
return render_template('index.html')
User class (user.py):
class User:
def __init__(self):
self._something = 0
@property
def get_something(self):
return self._something
@get_something.setter
def set_something(self, value):
self._something = value
And then the file who should use the getter:
import user
from app import user
# check if something is changed
# only it is changed
print(user.get_something)
Can you help me?