Sunday 15 January 2012

syntax - Python: Should I use a Constant or a Property? -


Which of the following two approaches is considered to be the best practice? Both get results.

  square fu (): LABELS = ('one', 'two', 'three') square bar (): def __init __ (self): self. __labels = ('one', 'two', 'three') @ property def labels (self): returns self label.    

If you do not need custom receiving or setting behavior, then there is no point in creating an asset first version is better.

Besides, these are not quite similar in their practice. In foo , there is a class-level attribute for the label in the bar , there is no reference to Foo.LABELS , it will work properly , Bar.labels .

No comments:

Post a Comment