Python does indeed have globals, but ...
Global variables are considered bad programming in all languages by seasoned programmers.
Here's one reason that kills their use (In my book):
Coupling between various methods (or functions). Assume the following:
Global variables are considered bad programming in all languages by seasoned programmers.
Here's one reason that kills their use (In my book):
Coupling between various methods (or functions). Assume the following:
- Method 1 sets global variable snoot to 4
- Method 2, which uses the contents of snoot, executes method 3 as a thread if snoot equals 4
Upon return from the thread, it checks the content of snoot,
if snoot equals anything other than 4, it prints message: 'method 3 was not executed'
otherwise it prints message: ''method 3 was successfully executed'.
- While the thread in method 2 was running, method 5 changed the global variable snoot to 2.
Method2 will see the '2' when thread completes, thus prints the wrong message.