there is a service (at flask), it accepts customer requests, there is a chain of functions that works with user variables. I need that in each they would be available without transmission in the parameters.
approximate structure of the application:
1. ls = "!" 2. @app.route('/<tx>') 3. def get_phrase(tx):#точка входа 4. ls = request.cookies.get('ls') 5. if True: 6. return get_info() 7. def get_info(): 8. return something_func(ls) line numbering for explanation.
if I write return ls between line 3 and line 4, I get the error UnboundLocalError: local variable 'ls' referenced before assignment (that is, can I not get the current value at any time?).
if I write after 4, the value obtained in line 4 will be returned regularly.
if return ls instead of 4 lines, then “!” is returned, i.e. global value.
but I need this value in all functions, i.e. in the example, I expect that by writing return ls between 7 and 8 lines I will get the value from the 4th line, however, the “!” is returned, that is, in the higher-level functions, the variable becomes local. How to change its value while preserving its globality?
lson the 4th line is not a global, but a local variable. To make it global, addglobal lsafter 3 lines - andreymalUnboundLocalError: local variable 'ls' referenced before assignmentis still not clear, why if I continue on the code as if I change the variable, then I can not get its value before these changes? - Maximmkaif True::? : D - gil9red