I wrote this function earlier to set the priority if the items in listwidget, however what I think would be more pythonic is to write get and set priority method...
how should i proceed with writing the method in a pythonic way ?
""" Reorder the items in the listWidget """
crntRow = newrow = self.listWidget.currentRow()
total = self.listWidget.count()
self.statusbar.showMessage("Total no. of items %s, and selected item number is %s"%(total,crntRow),2500)
if direction == 'up':
if crntRow > 0 : newrow -= 1
else: self.statusbar.showMessage("This is the first item cannot move up further.",1500)
elif direction == 'down':
if crntRow + 1 < total: newrow += 1
else: self.statusbar.showMessage("This is the last item cannot move down further.",1500)
if crntRow != newrow:
lines 5 and 6 have no effect as they set local variables and do not use them. Setters and getters are not considered very pythonic. Prefered way is to use attributes and replace those with calculated properties only after need arrices. However it is common that teachers of courses require those methods.
As Tony said getters and setters are not used in Python as it is inefficient to create a function just to change or return some variable when that can be done directly as the following example illustrates