What is the advantage of using static methods in Python?
Posted
by Curious2learn
on Stack Overflow
See other posts from Stack Overflow
or by Curious2learn
Published on 2010-03-13T13:19:52Z
Indexed on
2010/03/13
13:25 UTC
Read the original article
Hit count: 275
python
I ran into unbound method error in python with the code
class Sample(object):
'''This class defines various methods related to the sample'''
def drawSample(samplesize,List):
sample=random.sample(List,samplesize)
return sample
Choices=range(100)
print Sample.drawSample(5,Choices)
After reading many helpful posts here, I figured how I could add @staticmethod above to get the code working. I am python newbie. Can someone please explain why one would want to define static methods? Or, why are not all methods defined as static methods.
Thanks in advance.
© Stack Overflow or respective owner