Mar-31-2020, 06:49 PM
Two options, either one will require you to go through your code in some detail.
1. Don't use clf as a global. That's what I would prefer. Pass it as a parameter when needed and return it when needed.
2. Use clf as a global and get rid of it in all function calls. If it is global it does not need to be passed.
To see some of the issues you can fall into with globals, look at the following code
Fix is to do this:
That is SOOO prone to mistakes that are hard to find and code that is difficult to maintain. Which is why you need to go through your code and fix the globals one way or another.
1. Don't use clf as a global. That's what I would prefer. Pass it as a parameter when needed and return it when needed.
2. Use clf as a global and get rid of it in all function calls. If it is global it does not need to be passed.
To see some of the issues you can fall into with globals, look at the following code
global clf clf = 1 def fnc(): clf = 3 print(clf) fnc() print(clf)
Output:3
1
So how can clf be 3 inside the function but 1 outside?Fix is to do this:
global clf clf = 1 def fnc(): global clf clf = 3 print(clf) fnc() print(clf)
Output:3
3
Now changing clf inside the function changes it outside the function.That is SOOO prone to mistakes that are hard to find and code that is difficult to maintain. Which is why you need to go through your code and fix the globals one way or another.