arranging definitions
in python there is way to declare def
's without putting it in class. So, if i just need to store many def
's in separated class, i should simple do this:
def first_method():
pass
def s开发者_StackOverflowecond_method():
pass
and not use @classmethod
or @staticmethod
?:
class methods():
@classmethod
def first_method(cls):
pass
@staticmethod
def second_method():
pass
if first way is right, how should i mark private and public method?
Yes. Just keep functions that are not instance methods out of your classes.
You're thinking like you would in Java. Python isn't Java. Python has no true way to have public and private methods -- you can change the names to indicate that you'd like some form of privacy (_
or __
at the beginning of the name), but it's not enforceable.
I've found that in all the time I've programmed in Python, I never wished for access modifiers.
There is no such thing as private and public methods in Python. By convention, names that begin with a single underscore are considered "private", in a sense that user should not rely on their existence. Furthermore, you could document public interface. All the rest should of no relevance.
The set of mildly-related function would be a more pythonic solution, I'd say.
精彩评论