<p>这就是你如何使用装饰器。有关decorator如何工作的更多信息,请参见:<a href="https://www.datacamp.com/community/tutorials/decorators-python" rel="nofollow noreferrer">https://www.datacamp.com/community/tutorials/decorators-python</a>
<br/>
我建议您首先尝试更好地理解类和对象的概念。示例教程:<a href="https://www.w3schools.com/python/python_classes.asp" rel="nofollow noreferrer">https://www.w3schools.com/python/python_classes.asp</a>
<br/>
这篇文章还可以帮助您理解staticmethoddecorator是如何工作的<a href="https://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod">What is the difference between @staticmethod and @classmethod?</a></p>
<pre><code>from example import sample2
class sample1:
@staticmethod
def m1():
a='apple'
b='ball'
return sample2.m3(a,b)
@staticmethod
def m2():
a='ant'
b='bat'
c='cat'
return sample2.m3(a,b,c)
</code></pre>
<p>你知道吗示例.py带说明的文件:</p>
<pre><code>class sample2:
@staticmethod
def m3(a, b, c=None): # it works exactly the same as m3 function that is outside the class
print(a)
# this can be used without creating an object of sample2 class, example:
# sample2.m3(a="apple, b="ball")
def m3_method(self, a, b): # this one requires object on which it can be called
print(a)
# you have access to sample2 class object via self parameter, example of code:
# sample2_object = sample2() # you create object of sample2 class here
# sample2_object.m3_method(a="apple", b="ball") # you call m3_method on sample2_object here
def m3(a, b, c=None): # default value of c is add so you can either call it with 2 or 3 arguments
# example calls:
# m3("a", "b")
# m3("a", "b", "c")
print(a)
</code></pre>
<p>您应该能够运行这段代码,我认为它让您了解如何使用Python类。你知道吗</p>