让Python文件维护是一种不好的做法吗;“全球”;变量?

让Python文件维护是一种不好的做法吗;“全球”;变量?,python,Python,Globals.py dynamicValue = '' staticValue = 'This is a string' Controller.py import Globals.py print('The static value is: %s' % Globals.staticValue)) >> The static value is: This is a string someValue = 'i can assign this value to dynamicVa

Globals.py

dynamicValue = ''

staticValue = 'This is a string'
Controller.py

import Globals.py

print('The static value is: %s' % Globals.staticValue))
>> The static value is: This is a string

someValue = 'i can assign this value to dynamicValue'

Globals.dynamicValue = someValue

print('The dynamic value is: %s ' % Globals.dynamicValue))
>> The dynamic value is: i can assign this value to dynamicValue

我能够以这种方式维护我需要在各种方法和文件中使用的所有变量,并且它一直像一个符咒一样工作。我想知道为什么我没有看到这个方法被提及。。这种做法不好吗?

这在任何编程语言中都是不好的做法,不仅仅是Python。全局变量往往会产生不良的副作用


永远记住:能够做到这一点并不意味着你应该做到这一点。

这在任何编程语言中都是一种糟糕的做法,不仅仅是Python。全局变量往往会产生不良的副作用

永远记住:能够做到这一点并不意味着你应该做到。

使用全局变量(有副作用)与python没有特别的关系,它与你所遵循的编程范式有关。Python是多范式的,例如,您可能会看到在web上下文中使用的Python中的函数和oop范式,而您可能会说在数据科学或可视化中使用的命令式范式。使用全局变量(具有副作用)与Python并不是特别相关的,它与您所遵循的编程范式相关。Python是多范式的,例如,您可能会看到在web上下文中使用的Python中的函数和oop范式,而您可能会说在数据科学或可视化中使用的命令式范式。