Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含约 40 个函数的模块,它们都user作为关键字参数。
user
user在其中任何一个中都没有改变 - 在声明后它保持不变。
在函数之外声明user而不是将其传入,而是引用全局变量是否不合时宜user?
如果不了解更多关于您的用例,很难确定,但这听起来像是一个班级的工作:
class ComeUpWithAGoodName(object): def __init__(self, user): self.user = user def function1(self): do_stuff_with(self.user) # etc.