0

I am working in a project which uses pyqt4. Many place I see a situation like

class getWidget():
  @classmethod
  def get_line(cls,**args)
      return line(**args)

  @classmethod
  def get_label(cls,**args)
      return label(**args)

  @classmethod
  def get_button(cls,**args)
      return button(**args)





class line():
 ...
 ...

class label():
 ...
 ...

class button():
 ...
 ...

Whats the idea behind creating such a wrapper around BBB.

Jagat
  • 61
  • 7
  • why do you/they use `cls` instead of `self` ? – Stephane Rolland Jan 02 '14 at 19:56
  • These are class methods, So cls is used but this is just a convention, the place is important after the parentheses. – Jagat Jan 03 '14 at 09:27
  • No, you should not do this; `self` is what is expected and you'll confuse people by doing otherwise. The Python convention is to use `self`. It's told in books. You can read these SO questions http://stackoverflow.com/questions/4152850/is-it-possible-not-to-use-self-in-a-class and http://stackoverflow.com/questions/1984104/how-to-avoid-explicit-self – Stephane Rolland Jan 03 '14 at 13:49

1 Answers1

0

I don't see how it has anything to do with pyqt4.

If the author did not leave any documentation, we can only speculate his/her intention.

I guess it is very likely the original author wants to implement some sort of factory pattern such that he/she can write code like this:

b = AAA.get_BBB(param1, param2, param3)
Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
  • I thought it is some kind of programming trick/practice when making GUI application. That's why i mentioned pyqt. Thanks – Jagat Jan 02 '14 at 05:27