Answer the question
In order to leave comments, you need to log in
PEP 8: Class method before properties?
Good afternoon!
Usually it is customary to describe class methods after properties, the question will not be critical if you describe it before them, and not after? Namely in the django model:
def get_default_sound(self):
pass
class A(model.Model):
sound = models.CharField(_('Название'), max_length=255, default=get_default_sound)
class A(model.Model):
def get_default_sound(self):
pass
sound = models.CharField(_('Название'), max_length=255, default=get_default_sound)
Answer the question
In order to leave comments, you need to log in
exctac ,
1) you need to cut out pep-8 from tags
2) the question here is not in conventions but in the logic of your application
if the get_default_sound function is essentially static or should be rummaged between classes - then why not have it in one instance at the module level
if it is does not mess around with anyone - it is advisable not to take it out of the scope of the class,
as the classics said, "keep the definition as close to use as possible." this concerns not only the location of lines of code, but also the location in the stack of scopes,
so as for me, the issue here is not in agreements, but in the architecture of your application,
if you want to be consistent with django, then take a look here for example
https://docs.djangoproject. com/en/2.0/ref/contrib/...
Here are both options
class A(object):
@staticmethod
def get_val():
return 42
val = get_val.__func__()
print A.val
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question